返回题解分享
讨论 / 题解分享/ 帖子详情

顺子日期(结果填空) - 题解

#include<bits/stdc++.h>
using namespace std;

int shunzi( int a, int b, int c, int d) {

if (a == b - 1 && b == c - 1)
    return 1;
else if (b == c - 1 && c == d - 1)
    return 1;
else
    return 0;


}

int main() {
int num = 0;
int a, b, c, d;
for (int mouth = 1; mouth <= 12; mouth++)
for (int day = 1; day <= 31; day++) {
if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12);
else if (mouth == 2) {
if (day > 28)
break;
} else {
if (day > 30)
break;
}
a = mouth / 10, b = mouth % 10, c = day / 10, d = day % 10;
if (shunzi(a, b, c, d)) {
printf("2022-%d%d-%d%d\n",a, b, c, d);
num++;
}
}
cout << num << endl;
return 0;
}
0 回复 0 转发 0 喜欢 7 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!