欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

牛客网_PAT乙级1004_福尔摩斯的约会 (20)

程序员文章站 2022-07-15 10:30:05
...
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	char a[4][100];
	int i;//第i个字符串
	int size_1, size_2, size_3, size_4;
	int size_max, size_max34;
	int compare;
	char same_alpha_1_2;
	int flag = 0;
	char same_char_1_2;
	int same_num = 0;
	for (i = 0; i < 4; i++)
	{
		scanf("%s", a[i]);
	}

	//找前两个字符串第一对相同的大写英文字母
	size_1 = strlen(a[0]);
	size_2 = strlen(a[1]);
	size_max = (size_1 > size_2 ? size_1 : size_2);
	for (compare = 0; compare < size_max; compare++)
	{
		if (a[0][compare] == a[1][compare] && a[0][compare] >= 'A'&&a[0][compare] <= 'Z')
		{
			same_alpha_1_2 = a[0][compare];
			break;
		}
	}
	if (same_alpha_1_2 == 'A')printf("MON");
	else if (same_alpha_1_2 == 'B')printf("TUE");
	else if (same_alpha_1_2 == 'C')printf("WED");
	else if (same_alpha_1_2 == 'D')printf("THU");
	else if (same_alpha_1_2 == 'E')printf("FRI");
	else if (same_alpha_1_2 == 'F')printf("SAT");
	else if (same_alpha_1_2 == 'G')printf("SUN");
	printf(" ");
	//第二对相同的字符
	for (; compare < size_max; compare++)
	{
		if (a[0][compare] == a[1][compare])
		{
			if (flag == 1)
			{
				same_char_1_2 = a[0][compare];
				break;
			}
			else
			{
				flag = 1;
				continue;
			}
		}
	}
	if (same_char_1_2 >= '0'&&same_char_1_2 <= '9')
	{
		if (same_char_1_2 < '10')printf("0");
		printf("%c", same_char_1_2);
	}
	else
	{
		if (same_char_1_2 == 'A')printf("10");
		else if (same_char_1_2 == 'B')printf("11");
		else if (same_char_1_2 == 'C')printf("12");
		else if (same_char_1_2 == 'D')printf("13");
		else if (same_char_1_2 == 'E')printf("14");
		else if (same_char_1_2 == 'F')printf("15");
		else if (same_char_1_2 == 'G')printf("16");
		else if (same_char_1_2 == 'H')printf("17");
		else if (same_char_1_2 == 'I')printf("18");
		else if (same_char_1_2 == 'J')printf("19");
		else if (same_char_1_2 == 'K')printf("20");
		else if (same_char_1_2 == 'L')printf("21");
		else if (same_char_1_2 == 'M')printf("22");
		else if (same_char_1_2 == 'N')printf("23");
	}
	printf(":");
	//第一对相同字母
	size_3 = strlen(a[2]);
	size_4 = strlen(a[3]);
	size_max34 = (size_3 > size_4 ? size_3 : size_4);
	int alpha=0;
	for (compare = 0; compare < size_max; compare++)
	{
		if ((a[2][compare] >= 'A'&&a[3][compare] <= 'Z') || (a[2][compare] >= 'a'&&a[3][compare] <= 'z'))
		{
			alpha++;
		}
		if (a[2][compare] == a[3][compare] && ((a[2][compare] >= 'A'&&a[3][compare] <= 'Z') || (a[2][compare] >= 'a'&&a[3][compare] <='z')))
		{
			same_num = alpha;
			break;
		}
	}
	if (same_num < 10)printf("0");
	printf("%d", same_num);
	system("pause");
}
相关标签: 牛客网