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

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

cpp
#include <stdio.h>
#include <iostream>
#include <iomanip>

using namespace std;

int cmd(int year, int a, int b, int c, int d) {
if (year == a - 1 && a == b - 1)
return 1;

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

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

else
	return 0;


}

int cmd1( int b, int c, int d) {

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

else
	return 0;


}

int main() {
int num = 0, year = 2;
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 (cmd(year, a, b, c, d)) {

			cout << 2022 << setw(2) << setfill('0') << mouth << setw(2) << setfill('0') << day << endl;;
			num++;
		}


	}
cout << num << endl;
return 0;


}
0 回复 0 转发 1 喜欢 5 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!