pat 乙级 1044. 火星数字(20)


具体实现 : 见代码 


#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <ctime>

using namespace std;

string low[13]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string height[13]={"0","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string a[105];
int main() 
{
	int n;
	cin>>n;
	getchar();      // 记得吃掉  换行。
	for (int i=0;i<n;i++) {
		 getline(cin,a[i]);  // 因为有空格 所以 用getline;
	}
		 
	for (int i=0;i<n;i++) {

	    int len=a[i].length();
	    
	    if (isalpha(a[i][0])) {         			// 当输入的数字是火星文时 
	    	if (len>3) {             			//  >3 代表 两位     题目要求是0-169  所以 火星文 也只能是两位。
	    		string b1=a[i].substr(0,3);
	    		string b2=a[i].substr(4,len);
	    		int sum=0;
	    		for (int j=0;j<13;j++) {
	    			if (height[j]==b1) {
	    				sum+=j*13;
	    			}
	    		}

	    		for (int k=0;k<13;k++) {
	    			if (low[k]==b2) {
	    				sum+=k;
	    			}
	    		}
	    		cout<<sum<<endl;
	    	}
	    	else {
	    		for (int j=0;j<13;j++) {
	    			if (low[j]==a[i]) {
	    				cout<<j<<endl;
	    			}
	    			else if (height[j]==a[i]){
	    				cout<<j*13<<endl;
	    			}
	    		}
	    	} 
	    }

	    if(isdigit(a[i][0])) {               //     是地球文的时候 

	    	int num=0;
	    	for (int j=0;j<len;j++) {
	    		num*=10;
	    		num+=(int)(a[i][j]-48);   // 字符串转数字 
	    	}           

	    	if (num>=0&&num<13) {
	    		cout<<low[num]<<endl;
	    	}
	    	else{
	    		if (num%13==0) {
	    			cout<<height[num/13]<<endl;
	    		}
	    		else {
	    			cout<<height[num/13]<<" "<<low[num%13]<<endl;
	    		}
	    	}
	    }
    }
	return 0;
}

提交代码



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值