日期问题(C语言蓝桥杯2017年题目G)

分析:我们输入的AA/BB/CC有三种情况,所以我们编写一个函数,来判断三个数字作为 年 月 日是否合法,合法就输出,不合法就终止,还要查重,如果有相同的时间,就不重复打印,具体看代码注释。

复制代码
#include <stdio.h>
int num[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年  
int p(int a){
if((a%4==0&&a%100!=0)||a%400==0)return 1;//闰年 
else return 0;//平年	 
	}
int f(int a){//判断年是闰年还是平年 
	if(a>=60)return 1900+a;
	else return 2000+a;
}
void sc(int AA,int BB,int CC){
if(AA<100){//年-月-日  判断 
	   if(p(f(AA==0)))num[2]=28;//判断是平年还是闰年,然后来决定二月的天数 
	   else num[2]=29;//闰年 
		if(BB<=12){
			if(CC<=num[BB]){
				printf("%d-%02d-%02d",f(AA),BB,CC);
				return ;
			}
		}
	}
	return ;
}
int main(){
	int m,n,j,i,AA,BB,CC,s=0;
	scanf("%d%*c%d%*c%d",&AA,&BB,&CC);
	sc(AA,BB,CC);//假如输入的是  年  月  日 
	if(AA!=CC){
		printf("\n");不能重复,所以要进行判断 
	sc(CC,BB,AA);//假如输入的是  月  日  年 
	}
	if(AA!=BB){//不能重复,所以要进行判断 
		printf("\n");
	sc(CC,AA,BB);//假如输入的是  日  月  年
	} 
	return 0;
}
相关推荐
黄雪超2 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice2 小时前
对象的finalization机制Test
java·开发语言·jvm
思则变2 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
lijingguang2 小时前
在C#中根据URL下载文件并保存到本地,可以使用以下方法(推荐使用现代异步方式)
开发语言·c#
¥-oriented3 小时前
【C#中路径相关的概念】
开发语言·c#
CoderCodingNo3 小时前
【GESP】C++四级考试大纲知识点梳理, (7) 排序算法基本概念
开发语言·c++·排序算法
恋猫de小郭3 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
JosieBook3 小时前
【Java编程动手学】使用IDEA创建第一个HelloJava程序
java·开发语言·intellij-idea
Thomas_YXQ3 小时前
Unity3D DOTS场景流式加载技术
java·开发语言·unity
旷世奇才李先生4 小时前
Ruby 安装使用教程
开发语言·后端·ruby