C++信息學奧賽一本通-第一部分-基礎一-第3章-第1節
2051 偶數
#include <iostream>using namespace std;int main() {int number; cin >> number;if (number % 2 == 0) {cout << "yes";}
}
2052 范圍判斷
#include <iostream>using namespace std;int main() {int number; cin >> number;if (number > 1 && number < 100) {cout << "yes";}
}
2053 三個數
sort 是左閉右開 這里事實上是指針
#include <iostream>
#include <algorithm>using namespace std;int main() {int nums[3]; cin >> nums[0] >> nums[1] >> nums[2]; sort(nums, nums + 3);cout << nums[2] << " " << nums[1] << " " << nums[0] << endl;
}
2054 適合晨練
#include <iostream>using namespace std;int main() {int number; cin >> number;if (number >= 25 && number < 30) cout << "ok!";else cout << "no!";
}
2055 收費
#include <iostream>using namespace std;int main() {double weight; cin >> weight;double result;if (weight <= 20.0) result = 1.68 * weight;else result = 1.98 * weight;printf("%.2f", result);
}
2056 最大的數
#include <iostream>
#include <algorithm>using namespace std;int main() {double nums[3]; cin >> nums[0] >> nums[1] >> nums[2];sort(nums, nums + 3);cout << nums[2];
}
1039 判斷數正負
#include <iostream>using namespace std;int main() {long long num; cin >> num;if (num > 0) cout << "positive";else if (num < 0) cout << "negative";else cout << "zero";
}
1040 輸出絕對值
#include <iostream>
#include <cmath>using namespace std;int main() {double num; cin >> num;cout << abs(num);
}
1041 奇偶數判斷
#include <iostream>using namespace std;int main() {int number; cin >> number;if (number % 2 == 0) cout << "even";else cout << "odd";
}
1042 奇偶ASCII值判斷
#include <iostream>using namespace std;int main() {char ch; cin >> ch;if ((int)ch % 2 == 0) cout << "NO";else cout << "YES";
}
1043 整數大小比較
#include <iostream>using namespace std;int main() {long long a, b; cin >> a >> b;if (a > b) cout << ">";else if (a == b) cout << "=";else cout << "<";
}
1044 判斷是否為兩位數
#include <iostream>using namespace std;int main() {int num; cin >> num;if (num >= 10 && num <= 99) cout << "1";else cout << "0";
}
1045 收集瓶蓋贏大獎
#include <iostream>using namespace std;int main() {int a, b; cin >> a >> b;if (a >= 10 || b >= 20) cout << "1";else cout << "0";
}
1046 判斷一個數能否同時被3和5整除
#include <iostream>using namespace std;int main() {int num; cin >> num;if (num % 3 == 0 && num % 5 == 0) cout << "YES";else cout << "NO";
}
1047 判斷能否被3 5 7整除
#include <iostream>using namespace std;int main() {int num; cin >> num;if (num % 3 == 0) cout << "3" << " ";if (num % 5 == 0) cout << "5" << " ";if (num % 7 == 0) cout << "7" << " ";if (num % 3 != 0 && num % 5 != 0 && num % 7 != 0) cout << 'n';
}
1048 有一門課不及格的學生
#include <iostream>using namespace std;int main() {int a, b; cin >> a >> b;if ((a < 60 && b < 60) || (a >= 60 && b >= 60)) cout << "0";else cout << "1";
}