

题解:
#include <iostream>
using namespace std;
int main()
{
string str1,str2,str3,str4;
cin>>str1;
cin>>str2;
cin>>str3;
cin>>str4;
string DAY;
char hour;
int minute;
int m=0;
for(int i=0;i<int(str1.size());i++)
{
if(m==0&&str1[i]==str2[i]&&(str1[i]>='A'&&str1[i]<='G'))
{
DAY=str1[i];
m++;
continue;
}
if(m==1&&str1[i]==str2[i]&&(str1[i]>='0'&&str1[i]<='9'))
{
hour=str1[i];
break;
}
if(m==1&&str1[i]==str2[i]&&(str1[i]>='A'&&str1[i]<='N'))
{
hour=str1[i];
break;
}
}
for(int i=0;i<int(str3.size());i++)
{
if(str3[i]==str4[i]&&((str3[i]>='A'&&str3[i]<='Z')||(str3[i]>='a'&&str3[i]<='z')))
{
minute=i;
break;
}
}
if(DAY=="A") cout<<"MON";
if(DAY=="B") cout<<"TUE";
if(DAY=="C") cout<<"WED";
if(DAY=="D") cout<<"THU";
if(DAY=="E") cout<<"FRI";
if(DAY=="F") cout<<"SAT";
if(DAY=="G") cout<<"SUN";
cout<<' ';
if(hour>='A'&&hour<='N')
{
cout<<hour-65+10;
}
else
{
cout<<'0'<<hour;
}
cout<<':';
if(minute<10)
{
cout<<'0'<<minute;
}
else
{
cout<<minute;
}
}
//切记别忘记了continue和break,可以把他看成一个基本的习惯。
对于这种字符串比较中,第一个相等的字符,第二个相等的字符题,需要我们去用另一个计数。
优秀题解:
#include <bits/stdc++.h>
using namespace std;
string weeks[7] = {"MON ","TUE ","WED ","THU ","FRI ","SAT ","SUN "};
int main(){
string a,b,c,d;
cin >> a >> b >> c >> d;
char t[2];
int pos,i = 0,j = 0;
while(i < a.length() && i < b.length()){
if(a[i] == b[i] && (a[i] >= 'A' && a[i] <= 'G')){
t[0] = a[i];
break;
}
i++;
}
i++;
while(i < a.length() && i < b.length()){
if(a[i] == b[i] && ((a[i] >= 'A' && a[i] <= 'N') || isdigit(a[i]))){
t[1] = a[i];
break;
}
i++;
}
while(j < c.length() && j < d.length()){
if(c[j] == d[j] && isalpha(c[j])){
pos = j;
break;
}
j++;
}
cout << weeks[t[0] - 'A'];
int m = isdigit(t[1]) ? t[1] - '0' : t[1] - 'A' + 10;
printf("%02d:%02d",m,pos);
return 0;
}
作者:MilkLu
链接:https://www.acwing.com/solution/content/84350/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
1091

被折叠的 条评论
为什么被折叠?



