您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: