pat: 1014,部分错误


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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值