码迷,mamicode.com
首页 > 其他好文 > 详细

1100. Mars Numbers (20)

时间:2016-02-26 01:46:40      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

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\n",sum);
81         }
82     }
83     return 0;
84 }

 

1100. Mars Numbers (20)

标签:

原文地址:http://www.cnblogs.com/xiaoyesoso/p/5218871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!