分类讨论,不重不漏
#include <iostream>using namespace std;int main(){ int x; cin >> x; if (x > 0) cout << '+' << '\n'; if (x > 0) cout << '+' << '\n'; else cout << "-" << '\n'; if (x > 0) cout << '+' << '\n'; else if (x == 0) cout << '0' << '\n'; else cout << '-' << '\n'; if (x > 0) cout << '+'; else{ if (x == 0) cout << '0'; else cout << '-'; } //if嵌套,套一层而已 if (x >= 0){ if (x == 0) cout << '0' << '\n'; else cout << '+' << '\n'; } return 0;}
#include <bits/stdc++.h>using namespace std;int main(){ int a, b; cin >> a >> b; if (a >= 10 || b >= 20) cout << 1 << endl; else cout << 0 << endl; return 0;}
#include <bits/stdc++.h>using namespace std;int main(){ int n; cin >> n; if (n % 3 == 0 && n % 5 == 0) puts("YES"); else puts("NO"); return 0;}
//
// 百度百科,闰年// 普通闰年:公历年份是4的倍数,且不是100的倍数的,为闰年(如2004年、2020年等就是闰年)。// 世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是闰年,2000年是闰年)。// 能被4整除,不能被100整除的,是闰年// 能被400整除的,是闰年#include <bits/stdc++.h>using namespace std;int main(){ int n; cin >> n; if ((n % 4 == 0 && n % 100) || (n % 400 == 0)) puts("Y"); else puts("N"); return 0;}
// 本题对小学阶段有点麻烦,需要学习几下基本知识// 重点是阅读一下,我是如何用代码表达意思的#include <bits/stdc++.h>using namespace std;int main(){ double a, b, c; cin >> a >> b >> c; double delta = b * b - 4 * a * c; if (delta < 0) cout << "No answer!" << '\n'; else if (delta == 0){ printf("x1=x2=%.5lf\n", -b / (2 * a)); } else{ double x1 = (-b - sqrt(delta)) / (2 * a); double x2 = (-b + sqrt(delta)) / (2 * a); printf("x1=%.5lf;x2=%.5lf\n", min(x1, x2), max(x1, x2)); } return 0;}