PAT 1014 Holmes's date
Sherlock Holmes receives a strange note:
我们约会吧!
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
It soon became clear to the detective that the strange garble on the note was in fact the time of the appointment, Thursday at 14:04, because the first pair of identical uppercase English letters in the first two strings was the fourth letter D, for Thursday; The second pair of identical characters is E, which is the fifth letter of the English alphabet, representing the 14th hour of the day(so the 0 to 23 points of the day are represented by the numbers 0 through 9 and the capital letters A through N); The first pair of the same letter s appears in the fourth position(counting from 0), representing the fourth minute. Given two pairs of strings, please help Holmes decode the time of the appointment.
Input format:
Input four non-empty characters that do not contain Spaces and cannot exceed 60 characters in four lines.
Output format:
Output the appointment time in a line in the format of DAY HH:MM, where DAY is the 3-character abbreviation of a week, that is, MON indicates Monday, TUE indicates Tuesday, WED indicates Wednesday, THU indicates Thursday, FRI indicates Friday, and SAT indicates Saturday. SUN means Sunday. Question input ensures that a unique solution exists for each test.
Input example:
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
Output example:
THU 14:04
#include<bits/stdc++.h>
using namespace std;
int main() {
string a,b,c,d;
char z[10][20]= {"MON","TUE","WED","THU","FRI","SAT","SUN"};
char ch;
int i;
cin>>a>>b>>c>>d;
i=0;
int cnt=0;
while(cnt==0) {
if(a[i]==b[i]&&cnt==0&&a[i]>='A'&&a[i]<='G') {
cout<<z[a[i]-'A']<<" ";
cnt++;
}
i++;
}
while(cnt==1) {
if(a[i]==b[i]&&cnt==1) {
if(a[i]>='0'&&a[i]<='9') {
cout<<"0"<<a[i]<<":";
} else if(a[i]>='A'&&a[i]<='N') {
cout<<a[i]-'A'+10<<":";
}
cnt++;
}
i++;
}
i=0;
while(cnt==2) {
if(c[i]==d[i]&&((c[i]>='A'&&c[i]<='Z')||(c[i]>='a'&&c[i]<='z'))) {
if(i<10) cout<<"0";
cout<<i;
cnt++;
}
i++;
}
return 0;
}
Not sure what's wrong, tried several parameters are all correct
0 Answer
No answer yet
这家伙很懒,什么都没留下...