题目描述
解题思路
本题就是在两个字符串中查找相同的字符,对相同的元素进行解释它所代表的意思。
注意:
1.星期要控制字符的范围为
A到G
2.小时的范围为
0到9
,以及A到N
3.要
%02d
输出小时和分钟
代码
#include <stdio.h> int ret[4]; void find1(char* s1,char* s2) { int i =0,n=0; while (s1[i]&&s2[i]) { if (s1[i] == s2[i]) { if (s1[i] >= 'A' && s1[i] <= 'G') { ret[n++] = i; } else if(((s1[i] >= 'A' && s1[i] <= 'N') || (s1[i] >= '0' && s1[i] <= '9')) && n == 1) { ret[n++] = i; } } i++; } } void find2(char* s1, char* s2) { int i = 0; while (s1[i] && s2[i]) { if (s1[i] == s2[i]) { if ((s1[i] >= 'A' && s1[i] <= 'Z')|| (s1[i] >= 'a' && s1[i] <= 'z')) ret[0] = i; } i++; } } int main() { char a1[61], a2[61], b1[61], b2[61]; char* day[] = { "MON","TUE","WED","THU","FRI","SAT","SUN" }; scanf("%s%s%s%s", a1, a2, b1, b2); find1(a1, a2);//前两个串 //下面这个是处理小时问题 if (a1[ret[1]] >= 'A') ret[1] = a1[ret[1]] - 'A' + 10; else ret[1] = a1[ret[1]] - '0'; printf("%s %02d", day[a1[ret[0]]-'A'], ret[1]); find2(b1, b2);//后两个串 printf(":%02d", ret[0]); return 0; }