PAT乙级1044 火星数字

#include <cstdio>
#include <cstring>

char s1[][5] = {"", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char s2[][4] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};

int change(char a[4]){
	int b;
	for(int i = 1; i < 13; i++){
		if(strcmp(s1[i], a) == 0) b = i;
		else if(strcmp(s2[i], a) == 0) b = i * 13;
	}
	
	return b;
}

int main(){
	int n, temp;
	char str[10];
	scanf("%d\n", &n);
	while(n--){
		scanf("%[^\n]", str);
		getchar();
		if(str[0] >= '0' && str[0] <= '9'){	//如果是数字,则转化成火星文 
			sscanf(str, "%d", &temp);
			if(temp == 0) printf("tret");
			else{
				printf("%s", s2[temp / 13]);
				if(temp / 13 != 0 && temp % 13 != 0) printf(" ");
				printf("%s", s1[temp % 13]);
			}
			if(n > 0) printf("\n");
		}else{	//如果是火星文,则转换成数字 
			if(strlen(str) == 4) printf("0");	//四个字符的只能是零 
			else if(strlen(str) < 4){
				printf("%d", change(str));
			}else{	//由至少两个火星文组成的情况 
				char s1[4], s2[4];
				sscanf(str, "%s %s", s1, s2);
				printf("%d", change(s1) + change(s2));
			}
			if(n > 0) printf("\n");
		}
	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值