zoukankan      html  css  js  c++  java
  • PAT甲级——A1100 Mars Numbers

    People on Mars count their numbers with base 13:

    • Zero on Earth is called "tret" on Mars.
    • The numbers 1 to 12 on Earth 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 (<). 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


     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     string low[13]={//数字到火星文低位的映射
     5          "tret","jan","feb","mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
     6     string high[13]={//数字到火星文高位的映射
     7          "tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
     8     unordered_map<string,int>temp;//火星文到数字的映射
     9     for(int i=0;i<13;++i){
    10         temp[low[i]]=i;
    11         temp[high[i]]=i*13;
    12     }
    13     int n;
    14     scanf("%d%*c",&n);
    15     string digit="";
    16     while(n--){
    17         getline(cin,digit);
    18         if(isdigit(digit[0])){//如果是数字
    19             int k=stoi(digit);
    20             if(k/13!=0)//高位不为0,输出高位
    21                 printf("%s",high[k/13].c_str());
    22             if(k/13!=0&&k%13!=0)//高位低位均不为0,输出空格
    23                 printf(" ");
    24             if(k/13==0||k%13!=0)//高位为0或者高位不为0但低位为0时,输出低位
    25                 printf("%s",low[k%13].c_str());
    26             puts("");//换行
    27         }else{//是火星文
    28             int k=0;
    29             stringstream stream(digit);
    30             while(stream>>digit)//按空格键分割字符串
    31                 k+=temp[digit];
    32             printf("%d
    ",k);
    33         }
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    LightOJ 1313 Protect the Mines (Convex Hull && Minimum Circle)
    Hangzhou Invitation Day1
    hdu 2907 Diamond Dealer (Convex Hull)
    LightOJ 1239 Convex Fence (Convex Hull)
    POJ 2164 && LA 3218 Find the Border (Geometry, PSLG 平面直线图)
    hdu 1140 War on Weather (3DGeometry)
    uva 10347 Medians (Simple Geometry)
    String匹配函数
    动态读取外部文件
    转_读取外部数据
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11363523.html
Copyright © 2011-2022 走看看