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 }
  • 相关阅读:
    搜索文件/目录的shell脚本
    git的编译安装
    linux命令行直接执行MySQL/MariaDB语句查询
    MySQL重置root密码
    图解TCP/IP三次握手
    使用pull命令从Docker Hub仓库中下载镜像到本地
    BZOJ1051 [HAOI2006]受欢迎的牛(Tarjan缩点)
    BZOJ1026 [SCOI2009]windy数(数位DP)
    CERC2017 H Hidden Hierarchy(树+模拟)
    2018icpc徐州网络赛-H Ryuji doesn't want to study(线段树)
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/5218871.html
Copyright © 2011-2022 走看看