zoukankan      html  css  js  c++  java
  • 1044. 火星数字(20)

    1044. 火星数字(20)

    时间限制
    400 ms
    内存限制
    65536 kB

    火星人是以13进制计数的:

    • 地球人的0被火星人称为tret。
    • 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
    • 火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

    例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

    输入格式:

    输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。

    输出格式:

    对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

    输入样例:
    4
    29
    5
    elo nov
    tam
    
    输出样例:
    hel mar
    may
    115
    13

    分析:地球转火星用字符串数组,十位为n/13,个位为n%13;  注意:当将26(13的倍数)转为火星文时只输出一位hel(。。。)而不输出个位的tret(0)。
        火星转地球用map<string,int>记录每个火星文代表的数字,将各位代表的数字求和。
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 string marsR[]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
     5 string marsK[]={"0","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
     6 map<string,int> earthN;
     7 
     8 void toMars(int n){
     9     int k=n/13,r=n%13;
    10     if(k>0){
    11         cout<<marsK[k];
    12         if(r!=0) cout<<' ';
    13     } 
    14     if(r>0 || (r==0&&k==0)) cout<<marsR[r];///
    15     cout<<endl;
    16 }
    17 
    18 void toEarth(string s){
    19     stringstream ss(s);
    20     string t;
    21     int n=0;
    22     while(ss>>t) n+=earthN[t];
    23     cout<<n<<endl;
    24 }
    25 
    26 int main(){
    27     
    28     for(int i=0;i<13;i++){
    29         earthN[ marsR[i] ]=i;
    30         earthN[ marsK[i] ]=i*13; 
    31     }
    32     
    33     string s;
    34     int n;
    35     cin>>n;
    36     getchar();
    37     while(n--){
    38         getline(cin,s);
    39         if(isdigit(s[0])) toMars(stoi(s));
    40         else toEarth(s);
    41     }
    42     return 0;
    43 }
     
  • 相关阅读:
    二分+RMQ/双端队列/尺取法 HDOJ 5289 Assignment
    思维题 HDOJ 5288 OO’s Sequence
    树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
    最大流增广路(KM算法) HDOJ 1853 Cyclic Tour
    最大流增广路(KM算法) HDOJ 1533 Going Home
    最大流增广路(KM算法) HDOJ 2255 奔小康赚大钱
    Complete the Word CodeForces
    Gadgets for dollars and pounds CodeForces
    Vasya and Basketball CodeForces
    Carries SCU
  • 原文地址:https://www.cnblogs.com/Fresh--air/p/8593767.html
Copyright © 2011-2022 走看看