【題目連結】
ybt 1045:收集瓶蓋赢大獎
OpenJudge NOI 1.4 07:收集瓶蓋赢大獎
【題目考點】
1. 邏輯運算符:或 ||
邏輯表達式
a || b
- a與b的值都是false時,整個表達式的值是false。
- a或b的值為true時,整個表達式的值為true
2. if…else if…else語句
3. 輸出布爾型量
- 若布爾型量的值為true,會輸出1
- 若布爾型量的值為false,會輸出0。
【題解代碼】
解法1:使用邏輯表達式
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin>>a>>b;
if(a >= 10 || b >= 20)
cout<<1;
else
cout<<0;
return 0;
}
解法2:直接輸出邏輯表達式
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin>>a>>b;
cout<<(a >= 10 || b >= 20);
return 0;
}
解法3:使用if…else if…else語句
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin>>a>>b;
if(a >= 10)
cout<<1;
else if(b >= 20)
cout<<1;
else
cout<<0;
return 0;
}