zoukankan      html  css  js  c++  java
  • PAT1100:Mars Numbers

    1100. Mars Numbers (20)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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.分为地球数字转火星文、火星文转地球数字两种情况。
    2.火星文转地球数字分为三种情况:1)单独一个火星数字 2)两个火星数字(第二个火星数字不是tret) 3)两个火星数字(第二个火星数字一定是tret(零))。

    代码
    #include<iostream>
    #include<vector>
    #include<string>
    using namespace std;
    vector<string> num = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
    vector<string> highernum = {"sb","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok","mer", "jou"};
    
    
    int search(string s)
    {
        for(int i = 0;i < num.size();i++)
        {
            if(s == num[i])
                return i;
        }
    
        for(int i = 0;i < highernum.size();i++)
        {
            if(s == highernum[i])
                return -i;
        }
        return 0;
    }
    
    int main()
    {
        int N;
        scanf("%d",&N);
        getchar();
           while(N--)
           {
               string number;
               getline(cin,number);
               if(number[0] <= '9')
               {
                  int n = stoi(number);
                  int first = n/13,second = n % 13;
                  if(n == 0)
                    cout << num[n] <<endl;
                  else
                  {
                    if(first !=0 && second != 0)
                        cout << highernum[first]<< " " <<num[second] << endl;
                    else if(first != 0)
                      cout << highernum[first] << endl;
                    else if(second != 0)
                      cout << num[second] << endl;
                  }
    
    
               }
               else if(number.size() == 3)
               {
                    int res = search(number);
                    if(res >= 0)
                      cout << res <<endl;
                    else
                      cout << -res * 13 << endl;
               }
               else if(number.size() == 7)
               {
                   string fst = number.substr(0,3);
                   string sec = number.substr(4,3);
                   cout << -search(fst) * 13 + search(sec) << endl;
               }
               else
               {
                   string fst = number.substr(0,3);
                    cout << -search(fst) * 13 << endl;
               }
           }
    }
  • 相关阅读:
    Oracle把表记录恢复到指定时间节点
    解决Idea配置文件不显示中文的问题
    maven过滤配置文件
    文件流字符串互转
    jax-rs下载文件
    Excel导入异常Cannot get a text value from a numeric cell解决及poi导入时注意事项
    oracle获取表字段及表注释的相关操作
    pb SendMessage
    pb datawindow的用法
    charindex函数的用法
  • 原文地址:https://www.cnblogs.com/0kk470/p/7646783.html
Copyright © 2011-2022 走看看