PAT (Basic Level) Practice (中文) 1014 福尔摩斯的约会
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int MAXN = 65; 5 char a[MAXN],b[MAXN]; 6 int main(){ 7 int day,h,m,count=0,len=0,i; 8 day=0;h=0;m=0; 9 scanf("%s",a); 10 scanf("%s",b); 11 if(strlen(a)>strlen(b)) len = strlen(b); 12 else len = strlen(a); 13 for(i=0;i<len;i++){ 14 if((a[i]>='A'&&a[i]<='G')&&(a[i]==b[i])&&count==0){ 15 count++; 16 day = a[i]-'A'+1; 17 break; 18 } 19 20 } 21 for(int j=i+1;j<len;j++){ 22 if(count==1&&(a[j]==b[j])){ 23 24 if(a[j]>='0'&&a[j]<='9'){ 25 h = a[j]-'0'; 26 count++; 27 break; 28 } 29 else if(a[j]>='A'&&a[j]<='N'){ 30 h = a[j]-'A'+10; 31 count++; 32 break; 33 } 34 35 36 } 37 38 } 39 40 scanf("%s",a); 41 scanf("%s",b); 42 if(strlen(a)>strlen(b)) len = strlen(b); 43 else len = strlen(a); 44 count=0; 45 for(int i=0;i<len;i++){ 46 if(a[i]==b[i]&&count==0&&((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))){ 47 //if(a[i]==b[i]&&count==0&&((a[i]>='a'&&a[i]<='z'))){ 48 m = i; 49 count++; 50 break; 51 } 52 } 53 switch(day){ 54 case 1: printf("MON"); break; 55 case 2: printf("TUE"); break; 56 case 3: printf("WED"); break; 57 case 4: printf("THU"); break; 58 case 5: printf("FRI"); break; 59 case 6: printf("SAT"); break; 60 case 7: printf("SUN"); break; 61 } 62 printf(" %02d:%02d",h,m); 63 64 65 66 return 0; 67 }
关于星期几的问题是,考虑数字的范围,不应该只是大写字母。