Confusing Date Format UVALive 7711 给定mm-mm-mm格式的时间。年份(1900-1999)只给了后两位数,问有多少种合法的排列使时间正确。
2017-08-01 10:25
447 查看
/** 题目:Confusing Date Format UVALive 7711 链接:https://vjudge.net/contest/174844#problem/A 题意:给定mm-mm-mm格式的时间。年份(1900-1999)只给了后两位数,问有多少种合法的排列使时间正确。 思路: 第一次:快速读题,题意不清,没注意到这句话, To punish teams who did not read this problem statement carefully, we’ll add one trick input: if the input is “ 04-05-01 ”, the output should be 1 (not 6). 第二次:闰年判断写错了, 错的:if(y%4==0&&(y%100!=0||y%400==0)) 对的:if((y%4==0&&y%100!=0)||y%400==0) 。 第三次:没有判重,假设输入的数字是04-04-04,那么交换位置后,year,month,day会多次出现1904-04-04. */ #include<iostream> #include<cstdio> #include<algorithm> #include<map> #include<vector> #include<queue> #include<cstring> #include<cmath> using namespace std; typedef pair<int,int> P; typedef long long LL; const int N = 3e5+10; const int mod = 1e9+7; const int INF = 0x3f3f3f3f; int f[100][100][100]; bool ryear(int y) { if((y%4==0&&y%100!=0)||y%400==0){ return true; } return false; } int judge(int year,int month,int day) { if(f[year][month][day]) return 0; f[year][month][day] = 1; year += 1900; if(year>=2000||year<1900) return 0; if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){ if(day>=1&&day<=31) return 1; else return 0; } if(month==4||month==6||month==9||month==11){ if(day>=1&&day<=30) return 1; else return 0; } if(month==2){ if(ryear(year)){ if(day>=1&&day<=29) return 1; return 0; }else { if(day>=1&&day<=28) return 1; return 0; } } return 0; } int main(void) { int T; int cas = 1; cin>>T; int x, y, z; while(T--) { scanf("%d-%d-%d",&x,&y,&z); if(x==4&&y==5&&z==1){ printf("Case #%d: %d\n",cas++,1); continue; } memset(f, 0, sizeof f); int ans = 0; ans += judge(x,y,z); ans += judge(x,z,y); ans += judge(y,x,z); ans += judge(y,z,x); ans += judge(z,x,y); ans += judge(z,y,x); printf("Case #%d: %d\n",cas++,ans); } return 0; }
相关文章推荐
- UVALive - 7711 The 2016 ACM-ICPC Asia Jakarta Regional Contest A - Confusing Date Format
- (UVALive 7711)A - Confusing Date Format(水题,注意读题!)
- 时间戳格式化转换为日期格式,date.Format('yyyy/MM/dd hh:mm:ss')
- <fmt:formatDate value="${ abc}" pattern="hh:mma, MM/dd/yyyy" /> jstl 时间data格式
- Java日期转换SimpleDateFormat格式大全 和 判断是否为合法的日期时间字符串?
- 年月日时间格式转时间戳 ,ios系统不兼容 JS 中 = new Date(yyyy-mm-dd)方法
- mysql时间格式函数:from_unixtime()、unix_timestamp()、date_format()
- 用SimpleDateFormat类设置时间格式
- Mysql date_format()函数处理时间格式
- JavaScript下的时间格式处理函数Date.prototype.format
- Android SimpleDateFormat转换时间 12,24时间格式
- java中时间格式SimpleDateFormat的使用学习
- EasyUI的DataGrid日期列(datebox)正确显示json时间格式
- Calendar和SimpleDateFormat(打印指定时间和改变日期格式)
- 数据库时间格式,及nls_date_format
- 几种现在时间的获取方法和SimpleDateFormat匹配现在时间的格式
- SimpleDateFormat转换时间,12,24时间格式[转]
- 修改ORACLE-NLS_DATE_FORMAT时间格式的四种方式
- mysql时间格式DATE_FORMAT()
- 使用DateFormat把时间长度格式化为"时:分:秒"格式