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 }
  • 相关阅读:
    eval()一个有意思的PHP函数
    PHP error_reporting() 函数
    网络编程基础--协程--greenlet切换---gevent自动识别 IO ---
    网络编程基础--多线程---concurrent.futures 模块---事件Event---信号量Semaphore---定时器Timer---死锁现象 递归锁----线程队列queue
    rpm -qa 查找文件
    Linux Gvim shell 创建第一个shell脚本
    centos7修改网卡名称为eth0-技术流ken
    pxe+kickstart自动化批量安装系统详解-技术流ken
    cobbler单台服务器实现批量自动化安装不同版本系统-技术流ken
    cobbler批量安装系统使用详解-技术流ken
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/5218871.html
Copyright © 2011-2022 走看看