zoukankan      html  css  js  c++  java
  • 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
     1 #include<stdio.h>
     2 #include<string>
     3 #include<iostream>
     4 #include<string.h>
     5 #include<sstream>
     6 #include<vector>
     7 #include<map>
     8 using namespace std;
     9 char firwei[13][5]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    10 char secwei[13][5]={"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    11 map<string,int> mm1,mm2;
    12 void toMar(int n)
    13 {
    14     vector<string> vv;
    15     vv.push_back(firwei[n%13]);
    16     n = n / 13;
    17     if(n > 0)
    18     {
    19         vv.push_back(secwei[n]);
    20     }
    21     bool fir = 1;
    22     for(int i = vv.size() -1 ; i >= 0 ;--i )
    23     {
    24         if(fir)
    25         {
    26             cout << vv[i];
    27             fir = 0;
    28         }
    29         else if( vv [i] != "tret" )cout << " " << vv[i] ;
    30     }
    31     cout << endl;
    32 }
    33 
    34 int main()
    35 {
    36     int n;
    37     for(int i = 0 ;i < 13 ;++i)
    38     {
    39         mm1[firwei[i]] = i;
    40     }
    41     for(int i = 0 ;i < 13 ;++i)
    42     {
    43         mm2[secwei[i]] = i;
    44     }
    45     scanf("%d",&n);
    46     getchar();
    47     string str;
    48     for(int i = 0 ;i < n;++i)
    49     {
    50         getline(cin,str);
    51         if(str[0]>='0' && str[0] <= '9')
    52         {
    53             int num;
    54             stringstream ss;
    55             ss << str;
    56             ss >> num;
    57             toMar(num);
    58         }
    59         else
    60         {
    61             stringstream ss;
    62             vector<string> svv;
    63             string num;
    64             int sum = 0;
    65             ss << str;
    66             while(ss >> num)
    67             {
    68                 svv.push_back(num);
    69             }
    70             if(svv.size() > 1)
    71             {
    72                 sum = sum*13 + mm2[svv[0]];
    73                 sum = sum*13 + mm1[svv[1]];
    74             }
    75             else
    76             {
    77                 sum = sum*13 + mm2[svv[0]];
    78                 sum = sum*13 + mm1[svv[0]];
    79             }
    80             printf("%d
    ",sum);
    81         }
    82     }
    83     return 0;
    84 }
  • 相关阅读:
    IFNULL和isnull用法
    Python 进制转换 二进制 八进制 十进制 十六进制
    xhr是什么文件类型?
    from __future__ import unicode_literals
    sort is deprecated, use sort_values(inplace=True) for INPLACE sorting
    Autodesk View and Data API二次开发学习指南
    设置Mac 中保存对话框默认为扩展窗口
    [大数据学习研究] 错误排查,Hadoop集群部分DataNode不能启动
    IDEA 环境下更改Maven的仓库镜像提高下载速度
    [大数据学习研究] 4. Zookeeper-分布式服务的协同管理神器
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/5218871.html
Copyright © 2011-2022 走看看