C07-闰年判断
原题链接:49776.蒟蒻队笔记汇总2025-07-01 12:12:29
发布于:江苏
逻辑运算符 的结果是 0 或者 1
and or not
逻辑与:&&(and)
逻辑或:||(or)
逻辑非:!(not)
普通年份:2025 不能被100整除
世纪年份:1900, 2000, 2100, 2200 能被100整除
普通闰年:2020, 2024, 2028 被4整除
世纪闰年:2000, 2400 被400整除
#include<iostream>
using namespace std;
int main(){
int y;
cin >> y;
// 能被4整除的同时不能被100整除, 或者 能被400整除
if (y%4 == 0 && y%100 != 0 || y%400==0){
cout << "yes";
}
else {
cout << "no";
}
return 0;
}
一门课不及格
#include<iostream>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
// 语文不及格的同时数学得及格 或者 语文及格的同时数学不及格
if (a < 60 && b>=60 || a>=60 && b<60)
cout << 1;
else
cout << 0;
return 0;
}
某年某月
#include <iostream>
using namespace std;
int main() {
int y,m;
cin >> y >> m;
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){ //大月
cout << 31;
}
else if(m==4||m==6||m==9||m==11){ //小月
cout <<30;
}
else{ //二月
if (y%400==0 || y%4==0 && y%100 != 0){
cout << 29;
}else{
cout <<28;
}
}
return 0;
}
字符判断
#include<iostream>
using namespace std;
int main()
{
char a;
cin >> a;
if ('A'<=a && a<='Z') {
cout<<'A';
} else if ('a'<=a && a<='z') {
cout<<'a';
} else if ('0'<=a && a<='9') {
cout << '0';
} else {
cout << "other";
}
return 0;
}
这里空空如也
有帮助,赞一个