福尔摩斯的约会

#include<cstdio>
#include<cstdio>
#include<cstring>
	int main() {
		//定义一个二维字符数组来接受四个字符串,定义一个整型数组来确定字符数组的长度,并定义一个星期数组来输出星期几。
		char str[4][61];
		int len[4];
		char week[7][5] = { "MON", "TUE", "WED", "THU", " FRI", "SAT", "SUN" };
		for (int i = 0; i < 4; i++) {
			scanf("%s", str[i]);
			len[i] = strlen(str[i]);
		}

		//输出天,spe记录了数字。
		int spe;
		for (int i = 0; i < len[0] && i < len[1]; i++) {
			if (str[0][i] == str[1][i] && str[0][i] >= 'A' && str[0][i] <= 'G') {
				printf("%s", week[str[0][i] - 'A']);
				spe = i;
				break;
			}
		}

		//输出小时
		for (spe=spe+1; spe < len[0] && spe < len[1]; spe++) {
			if (str[0][spe] == str[1][spe]) {
				if (str[0][spe] >= '0' && str[0][spe] <= '9') {
					printf(" %02d", str[0][spe] - '0');
					break;
				}
				else if (str[0][spe] >= 'A' && str[0][spe] <= 'N') {
					printf(" %02d", str[0][spe] - 'A'+10);
					break;
				}
			}
		}

		//输出分钟
		for (int i = 0; i < len[2] && i < len[3]; i++) {
			if (str[2][i] == str[3][i]) {
				if ((str[2][i] >= 'a' && str[2][i] <= 'z') || (str[2][i] >= 'A' && str[2][i] <= 'Z')) {
					printf(":%02d", i);
					break;
				}
			}
		}

		return 0;


	}

  总共6个测试,我test0-3,5都是正确的,test4总是格式错误。

posted @ 2019-05-28 11:33  耿红军  阅读(149)  评论(0编辑  收藏  举报