Categories
不学无术

PAT 1100. Mars Numbers (20)

http://www.patest.cn/contests/pat-a-practise/1100
People on Mars count their numbers with base 13:

  • Zero on Earth is called “tret” on Mars.
  • The numbers 1 to 12 on Earch is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively.
  • For the next higher digit, Mars people name the 12 numbers as “tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou”, respectively.

For examples, the number 29 on Earth is called “hel mar” on Mars; and “elo nov” on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (< 100). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.
Output Specification:
For each number, print in a line the corresponding number in the other language.
Sample Input:

4
29
5
elo nov
tam

Sample Output:

hel mar
may
115
13

 
这题没什么技术含量,直接给代码(我写的肯定是史上最长哈哈哈)

#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		char* inStr = new char[8];
		scanf("%s", inStr);
		bool isInt = (inStr[0] >= '0' && inStr[0] <= '9');
		if (isInt)
		{
			int value = (int)strtol(inStr, NULL, 10);
			int high = value / 13;
			int low = value - 13 * high;
			switch (high)
			{
			case 0: break;
			case 1: printf("tam"); break;
			case 2: printf("hel"); break;
			case 3: printf("maa"); break;
			case 4: printf("huh"); break;
			case 5: printf("tou"); break;
			case 6: printf("kes"); break;
			case 7: printf("hei"); break;
			case 8: printf("elo"); break;
			case 9: printf("syy"); break;
			case 10:printf("lok"); break;
			case 11:printf("mer"); break;
			case 12:printf("jou"); break;
			default:
				break;
			}
			if (high > 0 && low > 0)
				printf(" ");
			switch (low)
			{
			case 0:
				if(high < 1)
					printf("tret");
				break;
			case 1: printf("jan"); break;
			case 2: printf("feb"); break;
			case 3: printf("mar"); break;
			case 4: printf("apr"); break;
			case 5: printf("may"); break;
			case 6: printf("jun"); break;
			case 7: printf("jly"); break;
			case 8: printf("aug"); break;
			case 9: printf("sep"); break;
			case 10:printf("oct"); break;
			case 11:printf("nov"); break;
			case 12:printf("dec"); break;
			default:
				break;
			}
		}
		else
		{
			bool nextFlag = true;
			int val = 0;
			if (strcmp(inStr, "tam") == 0)
				val = 1;
			else if (strcmp(inStr, "hel") == 0)
				val = 2;
			else if (strcmp(inStr, "maa") == 0)
				val = 3;
			else if (strcmp(inStr, "huh") == 0)
				val = 4;
			else if (strcmp(inStr, "tou") == 0)
				val = 5;
			else if (strcmp(inStr, "kes") == 0)
				val = 6;
			else if (strcmp(inStr, "hei") == 0)
				val = 7;
			else if (strcmp(inStr, "elo") == 0)
				val = 8;
			else if (strcmp(inStr, "syy") == 0)
				val = 9;
			else if (strcmp(inStr, "lok") == 0)
				val = 10;
			else if (strcmp(inStr, "mer") == 0)
				val = 11;
			else if (strcmp(inStr, "jou") == 0)
				val = 12;
			val *= 13;
			int chr = getchar();
			if (chr == ' ')
				scanf("%s", inStr);
			if (strcmp(inStr, "tret") == 0)
				val += 0;
			else if (strcmp(inStr, "jan") == 0)
				val += 1;
			else if (strcmp(inStr, "feb") == 0)
				val += 2;
			else if (strcmp(inStr, "mar") == 0)
				val += 3;
			else if (strcmp(inStr, "apr") == 0)
				val += 4;
			else if (strcmp(inStr, "may") == 0)
				val += 5;
			else if (strcmp(inStr, "jun") == 0)
				val += 6;
			else if (strcmp(inStr, "jly") == 0)
				val += 7;
			else if (strcmp(inStr, "aug") == 0)
				val += 8;
			else if (strcmp(inStr, "sep") == 0)
				val += 9;
			else if (strcmp(inStr, "oct") == 0)
				val += 10;
			else if (strcmp(inStr, "nov") == 0)
				val += 11;
			else if (strcmp(inStr, "dec") == 0)
				val += 12;
			printf("%d", val);
		}
		if (i < N - 1)
			printf("\n");
	}
	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.