zoukankan      html  css  js  c++  java
  • pat 1100

    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 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 map<string,int>mp1;
     4 map<string,int>mp2;
     5 string s;
     6 int  l;
     7 //mo 为余数,mar 为商 
     8 string mo[15]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
     9 string mar[15]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    10 void init()
    11 {
    12     for(int i =0;i<=12;i++){
    13         mp1[mar[i]] = i;
    14     }
    15     for(int  i =1;i<=12;i++){
    16         mp2[mo[i]] = i;
    17     } 
    18 }
    19 void zifu(string s)
    20 {
    21     int ans  = 0;
    22     for(int i =0;s[i];i++){
    23         ans  =ans*10+s[i]-'0';
    24     }
    25     int x=ans/13;int y= ans%13;
    26     if(x==0){
    27         cout<<mo[y]<<endl;
    28     }
    29     else{
    30         if(y==0){
    31             cout<<mar[x]<<endl;//如 : 13 :tam 后面没有tret 
    32         }
    33         else{
    34             cout<<mar[x]<<" "<<mo[y]<<endl;
    35         }
    36     }
    37 }
    38 void isnum(string s){
    39     string s1,s2;
    40     int  p=0,q=0;
    41     if(l<=3){//可能地球文字也可能火星文字 
    42         p=mp1[s];
    43         q=mp2[s];
    44     }
    45     else{
    46         s1 =s.substr(0,3);//从0开始数3个
    47         s2 =s.substr(4,3);
    48         p =mp1[s1];
    49         q =mp2[s2];
    50     }
    51     printf("%d
    ",p*13+q);
    52 }
    53 int main()
    54 {
    55     
    56     
    57     int n;
    58     scanf("%d",&n);
    59     getchar();
    60     while(n--){
    61         init(); 
    62         getline(cin,s);
    63         l =s.length();
    64         if(isdigit(s[0])){
    65             zifu(s);
    66         }
    67         else{
    68             isnum(s);
    69         }
    70     }
    71     return 0;
    72 }
  • 相关阅读:
    PHP chop() 函数
    PHP bin2hex() 函数
    多个表关联或者有视图套视图,快速检查SQL语句中所有的表统计信息是否过期
    洛谷P3628 [APIO2010]特别行动队 斜率优化
    洛谷P3195 [HNOI2008]玩具装箱TOY 斜率优化
    bzoj4282 慎二的随机数列 树状数组求LIS + 构造
    校园网 入读统计 + 性质分析
    HAOI2006 受欢迎的牛 缩点
    普通平衡树 Treap
    洛谷P1563 玩具谜题 简单模拟
  • 原文地址:https://www.cnblogs.com/tingtin/p/11545048.html
Copyright © 2011-2022 走看看