当前位置: 首页> 娱乐> 八卦 > 徐州个人建站模板_全球电子商务公司排行_南宁网站优化公司电话_如何推广公众号

徐州个人建站模板_全球电子商务公司排行_南宁网站优化公司电话_如何推广公众号

时间:2025/7/19 14:43:28来源:https://blog.csdn.net/XiaoBino_O/article/details/145958898 浏览次数:0次
徐州个人建站模板_全球电子商务公司排行_南宁网站优化公司电话_如何推广公众号

P8651 [P8651 [蓝桥杯 2017 省 B] 日期问题--注意日期问题中2月的天数 / if是否应该连用

      • 题目
  • 分析
      • 代码

题目

在这里插入图片描述

分析

代码中巧妙的用到3重循环,完美的解决了输出的顺序问题【题目要求从小到大】

需要注意的是2月的值,在不同的年份中应该更新2月的值

还有就是最后的3个if【T^T,我一开始写的3个if语句】,要么改成else if,要么把判定的条件改成用“||”连接【害我看半天T^T】,不然用3个if回导致重复输出

代码

#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <climits>  // 包含INT_MAX常量
#include <cctype>
using namespace std;int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int check(int x) {return (x % 4 == 0 && x % 100 != 0) || (x % 400 == 0);
}int main() {int a, b, c;scanf("%d/%d/%d", &a, &b, &c);//循环从早到晚,巧妙满足了题目要求的从早到晚排列for (int year = 1960; year <= 2059; year++) {if (check(year))month[2] = 29;elsemonth[2] = 28;for (int mth = 1; mth <= 12; mth++) {for (int day = 1; day <= month[mth]; day++) {if (a == year % 100 && b == mth && day == c)printf("%d-%02d-%02d\n", year, mth, day);else if (a == mth && b == day && c == year % 100 )printf("%d-%02d-%02d\n", year, mth, day);else if (a == day && b == mth &&  c == year % 100 )printf("%d-%02d-%02d\n", year, mth, day);}}}return 0;
}
关键字:徐州个人建站模板_全球电子商务公司排行_南宁网站优化公司电话_如何推广公众号

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: