http://pat.zju.edu.cn/contests/pat-b-practise/1014
A~G表示周几,0~9,A~N表示小时0~23,字符位置表示分钟0~59
#include<stdio.h>
#include <string.h>
#define SIZE 100
void printday(int x){
switch(x){
case 1: printf("MON "); break;
case 2: printf("TUE "); break;
case 3: printf("WED "); break;
case 4: printf("THU "); break;
case 5: printf("FRI "); break;
case 6: printf("SAT "); break;
case 7: printf("SUN "); break;
}
return ;
}
void printhour(char x){
if(x >='0' && x<='9'){
printf("%d", x-'0');
return;
}
else{
printf("%d", x-'A'+10);
return;
}
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
// freopen("E:\\out.txt", "w", stdout);
#endif
char a[SIZE], b[SIZE], c[SIZE], d[SIZE];
while(scanf("%s%s%s%s", a, b, c ,d) != EOF){
int i;
int len = strlen(a) > strlen(b) ? strlen(b):strlen(a);
for(i=0; i<len; i++){
if(a[i] >='A' && a[i] <='Z'){
if(a[i] == b[i]){
printday(a[i]-'A'+1);
break;
}
}
}//day
for(i++; i<len;i++){
if((a[i] >='A' && a[i] <='Z') || (a[i] >='0' && a[i] <='9')){
if(a[i] == b[i]){
printhour(a[i]);
break;
}
}
}//hour
printf(":");
len = strlen(c) > strlen(d) ? strlen(d):strlen(c);
for(i=0;i<len;i++){
if((a[i] >='A' && a[i] <='Z') || (a[i] >='a' && a[i] <='z')){
if(c[i] == d[i]){
printf("%02d\n", i);
break;
}
}
}//minute
}//while
return 0;
}
修改后,部分错误减少1个:
#include<stdio.h>
#include <string.h>
#define SIZE 100
void printday(int x){
switch(x){
case 1: printf("MON "); break;
case 2: printf("TUE "); break;
case 3: printf("WED "); break;
case 4: printf("THU "); break;
case 5: printf("FRI "); break;
case 6: printf("SAT "); break;
case 7: printf("SUN "); break;
}
return ;
}
void printhour(char x){
if(x >='0' && x<='9'){
printf("%02d", x-'0');//部分错误修改2:注意时间格式
return;
}
else{
printf("%02d", x-'A'+10);//部分错误修改1:注意时间格式
return;
}
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
// freopen("E:\\out.txt", "w", stdout);
#endif
char a[SIZE], b[SIZE], c[SIZE], d[SIZE];
while(scanf("%s%s%s%s", a, b, c ,d) != EOF){
int i;
int len = strlen(a) > strlen(b) ? strlen(b):strlen(a);
for(i=0; i<len; i++){
if(a[i] >='A' && a[i] <='Z'){
if(a[i] == b[i]){
printday(a[i]-'A'+1);
break;
}
}
}//day
for(i++; i<len;i++){
if((a[i] >='A' && a[i] <='Z') || (a[i] >='0' && a[i] <='9')){
if(a[i] == b[i]){
printhour(a[i]);
break;
}
}
}//hour
printf(":");
len = strlen(c) > strlen(d) ? strlen(d):strlen(c);
for(i=0;i<len;i++){
if((a[i] >='A' && a[i] <='Z') || (a[i] >='a' && a[i] <='z')){
if(c[i] == d[i]){
printf("%02d\n", i);
break;
}
}
}//minute
}//while
return 0;
}