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;
    //}

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

     
  • 相关阅读:
    buildroot的make menuconfig配置
    mac上如何设置ssh不断掉,并且session保持
    深度学习中网络设计的几点经验
    深度学习中将类别标签映射到one_hot向量
    python 过滤掉字符串中的回车符与换行符( )
    对训练集中的数据做随机抽样,并对抽样出的数据可视化观察分布情况
    利用Python的collections包下Counter的类统计每个数据出现的个数
    模型使用的数据集如何保证验证集和测试集的分布保持一致
    生成随机数的几个总结
    模型训练过程中的训练集、训练开发集、开发集和测试集总结
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10798597.html
Copyright © 2011-2022 走看看