地址
这道题很水 ,应该十分钟内就解决 。但是我的思路比较僵硬, 想用if来判断星期几 , 然后就发现WA了。然后换成用char数组来存字母 , 在对天数做处理就过了。
第一次代码:
#include <iostream>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <vector>
#include<cstdio>
using namespace std;
int main( )
{
int t;
cin >>t;
while(t--){
long long year , month , date ;
string s;
cin >>year >>month >>date;
cin >>s;
long long year1 , month1 , date1 ;
cin >>year1 >>month1 >>date1;
long long sum = (year1 - year)*360 + (month1 - month)*30 + date1- date;
if(sum<0)
sum = -sum;
if(sum%5==0)
{
cout<<s<<endl;
}
else if(sum%5==1){
if(s=="Monday")
cout<<"Tuesday"<<endl;
else if(s=="Tuesday")
cout<<"Wednesday"<<endl;
else if(s=="Wednesday")
cout<<"Thursday"<<endl;
else if(s=="Thursday")
cout<<"Friday"<<endl;
else
{
cout<<"Monday"<<endl;
}
}
else if(sum%5==2){
if(s=="Monday")
cout<<"Wednesday"<<endl;
else if(s=="Tuesday")
cout<<"Thursday"<<endl;
else if(s=="Wednesday")
cout<<"Friday"<<endl;
else if(s=="Thursday")
cout<<"Monday"<<endl;
else
{
cout<<"Tuesday"<<endl;
}
}
else if(sum%5==3){
if(s=="Monday")
cout<<"Thursday"<<endl;
else if(s=="Tuesday")
cout<<"Friday"<<endl;
else if(s=="Wednesday")
cout<<"Monday"<<endl;
else if(s=="Thursday")
cout<<"Tuesday"<<endl;
else
{
cout<<"Wednesday"<<endl;
}
}
else if(sum%5==4){
if(s=="Monday")
cout<<"Friday"<<endl;
else if(s=="Tuesday")
cout<<"Monday"<<endl;
else if(s=="Wednesday")
cout<<"Tuesday"<<endl;
else if(s=="Thursday")
cout<<"Wednesday"<<endl;
else
{
cout<<"Thursday"<<endl;
}
}
}
return 0;
}
/**/
第二次代码:
#include <iostream>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <vector>
#include<cstdio>
using namespace std;
string daytable[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
int main( )
{
int t;
cin >>t;
for(int j=0;j<t;j++){
long long year , month , date ;
string s;
cin >>year >>month >>date;
cin >>s;
long long year1 , month1 , date1 ;
cin >>year1 >>month1 >>date1;
long long sum = (year1 - year)*360 + (month1 - month)*30 + date1- date;
sum %=5;
if(sum<0)
sum +=5;
int now =0;
for(int i=0;i<5;i++){
if(daytable[i]==s){
now =i;
break;
}
}
cout<<daytable[(now + sum)%5]<<endl;
}
return 0;
}
/**/