zoukankan      html  css  js  c++  java
  • PAT 1100 Mars Numbers

    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 Earth 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 (<). 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

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    vector<string> vec2 = {"tret","jan","feb","mar","apr","may","jun","jly","aug"
    ,"sep","oct","nov","dec"};
    
    vector<string> vec1 = {"","tam","hel","maa","huh","tou","kes"
    ,"hei","elo","syy","lok","mer","jou"};
    
    
    int to_int(string s){
        int sum = 0;
        for(int i=0;i < s.size();i++){
            sum = sum*10 + (s[i]-'0');
        }
        return sum;
    }
    
    
    int main(){
        map<string,int> mp;
        for(int i=0;i <= 12;i++){
            mp[vec2[i]] = i;
        }
        for(int i=13;i <= 24;i++){
            mp[vec1[i-12]] = i;
        }
        int t;
        cin >> t;getchar();
    
        while(t--){
            string s;
            getline(cin,s);
            if(s[0] >= '0' && s[0] <= '9'){
                int num = to_int(s);
                if(num < 13) cout << vec2[num] << endl;
                else{
                    int shiwei = num/13;
                    int gewei = num%13;
                    if(gewei != 0)
                        cout << vec1[shiwei] << " " << vec2[gewei] << endl;
                    else
                        cout << vec1[shiwei] << endl;
    
                }
            }
            else {
                if(s.size() < 5){
                    if(mp[s] < 13)
                    cout << mp[s] << endl;
                    else
                        cout << (mp[s]-12)*13 << endl;
                }
                else{
                    string s1 = s.substr(0,3);
                    string s2 = s.substr(4,3);
                    cout << (mp[s1]-12)*13+mp[s2] << endl;
                }
            }
        }
    
        return 0;
    }
    
    
    
    
    
    
    
    
    
    //#include <iostream>
    //#include <string>
    //using namespace std;
    //string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    //string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    //string s;
    //int len;
    //void func1(int t) {
    //    if (t / 13) cout << b[t / 13];
    //    if ((t / 13) && (t % 13)) cout << " ";
    //    if (t % 13 || t == 0) cout << a[t % 13];
    //}
    //void func2() {
    //    int t1 = 0, t2 = 0;
    //    string s1 = s.substr(0, 3), s2;
    //    if (len > 4) s2 = s.substr(4, 3);
    //    for (int j = 1; j <= 12; j++) {
    //        if (s1 == a[j] || s2 == a[j]) t2 = j;
    //        if (s1 == b[j]) t1 = j;
    //    }
    //    cout << t1 * 13 + t2;
    //}
    //int main() {
    ////    int n;
    ////    cin >> n;
    ////    getchar();
    //    freopen("a","r",stdin);
    //    for (int i = 0; i < 168; i++) {
    //        s = to_string(i);
    //        len = s.length();
    //        if (s[0] >= '0' && s[0] <= '9')
    //            func1(stoi(s));
    //        else
    //            func2();
    //        cout << endl;
    //    }
    //    return 0;
    //}

    就是整除位都是单个字符串,在字符串变数字的时候没有考虑到。。

     
  • 相关阅读:
    日报11.1
    CCC2020 Surmising a Sprinter's Speed
    3D扫雷 (3D Minesweeper)
    如何使用小米手环与PN532(或类似芯片)复制验证卡号的IC卡
    分享一个api:随机二次元图片
    NOIP2017 时间复杂度 大模拟
    《区块链100问》笔记整理——42~49问
    Coursera-AndrewNg(吴恩达)机器学习笔记——第四周编程作业(多分类与神经网络)
    Coursera-AndrewNg(吴恩达)机器学习笔记——第四周
    《区块链100问》笔记整理——23~41问
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10798597.html
Copyright © 2011-2022 走看看