PTA 乙级 1044 火星数字

代码实现:

#include
#include
#include

int main()
{
	char *mars_number1[13] = { "tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec" },
		 *mars_number2[13] = { "","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou" };
	int N;

	scanf("%d", &N); getchar();
	for (int i = 0; i < N; i++)
	{
		char num[8];
		int int_num = 0;
		gets(num);
		if (num[0] >= '0'&&num[0] <= '9')
		{
			int_num = atoi(num);
			if (int_num < 13)printf("%s\n", mars_number1[int_num]);
			else if (int_num % 13 == 0)printf("%s\n", mars_number2[int_num / 13]);
			else printf("%s %s\n", mars_number2[int_num / 13], mars_number1[int_num % 13]);
		}
		else
		{
			int flag = 0;
			for (int j = 0; j < 13; j++)
				if (strcmp(num, mars_number1[j]) == 0)printf("%d\n", j), flag = 1;
			for (int j = 1; j < 13; j++)
				if (strcmp(num, mars_number2[j]) == 0)printf("%d\n", j * 13), flag = 1;
			if (flag == 0)
			{
				num[3] = 0;
				for (int j = 1; j < 13; j++)
					if (strcmp(num, mars_number2[j]) == 0)int_num += j * 13;
				for (int j = 0; j < 13; j++)
					if (strcmp(num + 4, mars_number1[j]) == 0)int_num += j;
				printf("%d\n", int_num);
			}
		}
	}

	return 0;
}

你可能感兴趣的:(PTA,Basic,Level,Practice)