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

来源:互联网 发布:php get传递url 编辑:程序博客网 时间:2024/06/05 00:17


具体实现 : 见代码 


#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;}

提交代码