zoukankan      html  css  js  c++  java
  • PAT 1100 Mars Numbers (20)

    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

    思路:用string数组来保存火星数, 用map保存火星数对应的阿拉伯数字;
    当输入时火星数,判断是有还有第二个输入的办法:如果输入的第一个字符串是0-12对应的火星数,则肯定没有第二个字符串输入;
    若不满足上以条件, 则再吸收一个字符,判断是否是' ', 若是则表示输入结束, 反之则表示还有一个字符串
    当输入的是阿拉伯数字的时候, 只需要判断第一位是否是0-9的字符就能判断, 字符串的长度,由''出现的位置决定
    注意点:单独处理输入数字为0的情况
     1 #include<iostream>
     2 #include<vector>
     3 #include<map>
     4 using namespace std;
     5 string ch1[]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
     6 string ch2[]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
     7 map<string, int> m1, m2;
     8 
     9 int main(){
    10   int n, i;
    11   cin>>n;
    12   for(i=0; i<13; i++) m1[ch1[i]] = i;
    13   for(i=0; i<13; i++) m2[ch2[i]] = i*13;
    14   for(i=0; i<n; i++){
    15     string a, b;
    16     cin>>a;
    17     if(a[0]<='9' && a[0]>='0'){
    18       int temp=0, cnt=0;
    19       while(a[cnt]!='') temp = temp*10 + (a[cnt++]-'0');
    20       if(temp/13) {
    21         cout<<ch2[temp/13];
    22         if(temp%13) printf(" ");
    23         else cout<<endl;
    24       }
    25       if(temp%13) cout<<ch1[temp%13]<<endl;
    26       if(temp==0) cout<<ch1[0]<<endl;
    27     }else{
    28       int sum=0;
    29       if(m2.count(a)){
    30         sum += m2[a];
    31         if(cin.get()!='
    ') cin>>b;
    32         sum += m1[b];;
    33       }else sum += m1[a];
    34       cout<<sum<<endl;
    35     }
    36   }
    37   return 0;
    38 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    《iBoard 是什么》之简介
    [iBoard 电子学堂][第八卷 设计任意波发生器]第一篇 iBoard 任意波发生器简介
    [iBoard 电子学堂][第〇卷 电子基础]第二篇 电路图与印刷电路板
    职业规划提示
    督查督办工作基本程序
    今天收拾了个电脑抽屉,发现原来我是个有钱人
    VB之SendKeys键盘模拟
    天骄辅助外挂制作,寻求合作
    用CE找武林外传一级基址的方法
    asp实现数据记录的备份及恢复抛砖引玉
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9232117.html
Copyright © 2011-2022 走看看