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 }
  • 相关阅读:
    Linux 安全工具之extundelete误删除恢复
    Linux安全工具之fail2ban防爆力破解
    构建高效安全的Nginx Web服务器
    必读说明
    U盘因格式化 NTFS 中断造成无法识别,生产平台同样无法识别的修复处理方案
    计算机等级考试【二级C语言程序设计】知识点整理
    MD 使用 i5ting_toc 转换成 HTML
    Windows10 图标变白修复
    【已解决】老型号电脑需要按F1键才能进入系统
    【已解决】什么是心跳包?
  • 原文地址:https://www.cnblogs.com/tingtin/p/11545048.html
Copyright © 2011-2022 走看看