<style>
html, body, .ui-content {
background-color: #333;
color: #ddd;
}
body > .ui-infobar {
display: none;
}
.ui-view-area > .ui-infobar {
display: block;
}
.markdown-body h1{
color: #9CCEF2;
}
.markdown-body h2,
.markdown-body h3{
color: #B1D6CA;
}
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
color: #ddd;
}
.markdown-body h1,
.markdown-body h2 {
border-bottom-color: #ffffff69;
}
.markdown-body h1 .octicon-link,
.markdown-body h2 .octicon-link,
.markdown-body h3 .octicon-link,
.markdown-body h4 .octicon-link,
.markdown-body h5 .octicon-link,
.markdown-body h6 .octicon-link {
color: #fff;
}
.markdown-body img {
background-color: transparent;
}
.ui-toc-dropdown .nav>.active:focus>a, .ui-toc-dropdown .nav>.active:hover>a, .ui-toc-dropdown .nav>.active>a {
color: white;
border-left: 2px solid white;
}
.expand-toggle:hover,
.expand-toggle:focus,
.back-to-top:hover,
.back-to-top:focus,
.go-to-bottom:hover,
.go-to-bottom:focus {
color: white;
}
.ui-toc-dropdown {
background-color: #333;
}
.ui-toc-label.btn {
background-color: #191919;
color: white;
}
.ui-toc-dropdown .nav>li>a:focus,
.ui-toc-dropdown .nav>li>a:hover {
color: white;
border-left: 1px solid white;
}
.markdown-body blockquote {
color: #bcbcbc;
}
.markdown-body table tr {
background-color: #5f5f5f;
}
.markdown-body table tr:nth-child(2n) {
background-color: #4f4f4f;
}
.markdown-body code,
.markdown-body tt {
color: #eee;
background-color: rgba(230, 230, 230, 0.36);
}
a,
.open-files-container li.selected a {
color: #5EB7E0;
}
</style>
###### tags: `tgirc早修book`
# Ch.02 題目練習
## if else
<font color="FEA0A0">**題目**</font>
1. [Zerojudge d064: ㄑㄧˊ 數?](https://zerojudge.tw/ShowProblem?problemid=d064)
2. [Zerojudge a003: 兩光法師占卜術](https://zerojudge.tw/ShowProblem?problemid=a003)
3. [Zerojudge d485: 我愛偶數](https://zerojudge.tw/ShowProblem?problemid=d485)
4. [Zerojudge d065: 三人行必有我師](https://zerojudge.tw/ShowProblem?problemid=d065)
5. [Zerojudge d066: 上學去吧!](https://zerojudge.tw/ShowProblem?problemid=d066)
6. [Zerojudge a006: 一元二次方程式](https://zerojudge.tw/ShowProblem?problemid=a006)
:::spoiler <font color="FEA0A0">**題解**</font>
1. [Zerojudge d064: ㄑㄧˊ 數?](https://zerojudge.tw/ShowProblem?problemid=d064)
```cpp=
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
if(n % 2 ==0){
cout << "Even";
}
else{
cout << "Odd";
}
return 0;
}
```
##
2. [Zerojudge a003: 兩光法師占卜術](https://zerojudge.tw/ShowProblem?problemid=a003)
```cpp=
#include <iostream>
using namespace std;
int main()
{
int M, D, S;
cin >> M >> D;
S = (M * 2 + D) % 3;
if (S == 0){
cout << "普通\n";
}
else if (S == 1){
cout << "吉\n";
}
else {
cout << "大吉\n";
}
return 0;
}
```
##
3. [Zerojudge d485: 我愛偶數](https://zerojudge.tw/ShowProblem?problemid=d485)
```cpp=
#include<iostream>
using namespace std;
int main(){
int a, b, ans;
cin >> a >> b;
ans = b/2 - a/2;
ans += (a+1)%2;
cout << ans;
return 0;
}
```
##
4. [Zerojudge d065: 三人行必有我師](https://zerojudge.tw/ShowProblem?problemid=d065)
```cpp=
#include<iostream>
using namespace std;
int main(){
int in, max=0;
for(int i = 0; i < 3; i++){
cin >> in;
if(in > max){
max = in;
}
}
cout << max;
return 0;
}
```
##
5. [Zerojudge d066: 上學去吧!](https://zerojudge.tw/ShowProblem?problemid=d066)
```cpp=
#include<iostream>
using namespace std;
int main(){
int hh, mm;
cin >> hh >> mm;
if(hh>=8 && hh<=16){
cout << "At School" << endl;
}
else if(hh == 7){
if(mm >= 30){
cout << "At School" << endl;
}
else{
cout << "Off School" << endl;
}
}
else{
cout << "Off School" << endl;
}
return 0;
}
```
##
6. [Zerojudge a006: 一元二次方程式](https://zerojudge.tw/ShowProblem?problemid=a006)
```cpp=
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int a, b, c;
int x1, x2; //兩解
int d; //判別式
cin >> a >> b >> c;
d = sqrt( b*b - 4*a*c ); //判別式
if(d>0){ //判別式>0,兩實根
x1 = (-b + d) / (2*a);
x2 = (-b - d) / (2*a);
cout << "Two different roots x1=" << x1 << " , x2=" << x2;
}
else if(d == 0){ //判別式=0,重根
x1 = (-b) / (2*a);
cout << "Two same roots x=" << x1;
}
else{ //判別式<0,無實根
cout << "No real root";
}
return 0;
}
```
:::