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

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

     
  • 相关阅读:
    lucene中创建索引库
    商城后台上架商品列表查询的书写全过程
    Linux命令英文全称
    商品品牌分页、过滤、排序查询的完成流程
    axios使用步骤详解(附代码)
    使用CORS处理跨域请求
    npm 是干什么的?
    Mybatis通用Mapper介绍和使用
    FastDFS的理解和分析
    CDN服务的含义
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10798597.html
Copyright © 2011-2022 走看看