浙大PAT甲级 1061

时间:2022-03-20 15:21:26

简单题,先用map<int,string>现将星期与星期的英文相对应。然后根据题意查找相等的字符。

AC代码:

#include<iostream>
#include<map>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<list>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
using namespace std;
string s1,s2,s3,s4;
map<int,string> m;
void init()
{
m[1]="MON";
m[2]="TUE";
m[3]="WED";
m[4]="THU";
m[5]="FRI";
m[6]="SAT";
m[7]="SUN";
}
int main()
{
init();
cin>>s1>>s2>>s3>>s4;
int i;
for(i=0;i<min(s1.size(),s2.size());i++)
{
if(s1[i]==s2[i]&&s1[i]>='A'&&s1[i]<='G')
{
cout<<m[s1[i]-'A'+1]<<" ";
break;
}
}
i++;
for(;i<min(s1.size(),s2.size());i++)
{
if(s1[i]==s2[i])
{
if(s1[i]>='0'&&s1[i]<='9')
{
printf("%02d:",s1[i]-'0');
break;
}
else if(s1[i]>='A'&&s1[i]<='N')
{
printf("%d:",s1[i]-'A'+10);
break;
}
}
}
for(i=0;i<min(s3.size(),s4.size());i++)
{
if(s3[i]==s4[i]&&((s3[i]>='a'&&s3[i]<='z')||(s3[i]>='A'&&s3[i]<='Z')))
{
printf("%02d",i);
break;
}
}
}