zoukankan      html  css  js  c++  java
  • 【算法笔记】B1044 火星数字

    1044 火星数字 (20 分)
     

    火星人是以 13 进制计数的:

    • 地球人的 0 被火星人称为 tret。
    • 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
    • 火星人将进位以后的 12 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

    例如地球人的数字 29 翻译成火星文就是 hel mar;而火星文 elo nov 对应地球数字 115。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

    输入格式:

    输入第一行给出一个正整数 N(<),随后 N 行,每行给出一个 [0, 169) 区间内的数字 —— 或者是地球文,或者是火星文。

    输出格式:

    对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

    输入样例:

    4
    29
    5
    elo nov
    tam
    

    输出样例:

    hel mar
    may
    115
    13

    思路:

    直接计算出所有数字的映射,就可以直接查询输出了。13的倍数对应的火星数字是tam,hel,maa…而不是tam tret,hel tret,maa tret…

     codes:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 string str1[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
     4 string str2[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
     5 map<int, string> toMars;
     6 map<string, int> toNums;
     7 void init(){
     8     for(int i = 0; i < 13; i++){
     9         toMars[i] = str1[i];
    10         toNums[str1[i]] = i;
    11     }
    12     for(int i = 13; i < 169; i++){
    13         string s;
    14         if(i%13 == 0) s = str2[i / 13];
    15         else s = str2[i / 13] + ' ' + str1[i % 13];
    16         toMars[i] = s;
    17         toNums[toMars[i]] = i;
    18     }
    19 }
    20 
    21 int main(){
    22     init();
    23     int n;
    24     scanf("%d", &n);
    25     getchar();
    26     for(int i = 0; i < n; i++){
    27         string str;
    28         getline(cin, str);
    29         if(str[0]>='0'&&str[0]<='9'){
    30             int num = 0; 
    31             for(int j = 0; j < str.length(); j++){
    32                 num = num * 10 + (str[j] - '0');
    33             }
    34             cout<<toMars[num]<<endl;
    35         }else{
    36             cout<<toNums[str]<<endl;
    37         }
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    Hdu 5396 Expression (区间Dp)
    Lightoj 1174
    codeforces 570 D. Tree Requests (dfs)
    codeforces 570 E. Pig and Palindromes (DP)
    Hdu 5385 The path
    Hdu 5384 Danganronpa (AC自动机模板)
    Hdu 5372 Segment Game (树状数组)
    Hdu 5379 Mahjong tree (dfs + 组合数)
    Hdu 5371 Hotaru's problem (manacher+枚举)
    Face The Right Way---hdu3276(开关问题)
  • 原文地址:https://www.cnblogs.com/chunlinn/p/10631737.html
Copyright © 2011-2022 走看看