zoukankan      html  css  js  c++  java
  • 1100 Mars Numbers (20 分)

    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 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
    思路
      整13倍后面没有零,刚开始想错了。比如26是hel而不是hel tret
    #include<iostream>
    #include<vector>
    #include<algorithm>
    #include<map>
    #include<set>
    #include<cmath>
    #include<climits>
    #include<sstream>
    using namespace std;
    string num1[]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    string num2[]={" ","tam", "hel", "maa", "huh", "tou"
    , "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    
    void solve1(string &num)
    {
        int temp=stoi(num);
        if(temp<13)
            cout<<num1[temp]<<endl;
        else if(temp==13)
            cout<<"tam"<<endl;
        else
        {
            int a=temp/13;
            int b=temp%13;
            if(b!=0)
                cout<<num2[a]<<" "<<num1[b]<<endl;
            else
                cout<<num2[a]<<endl;
        }
    
    }
    
    void solve2(string &num)
    {
        if(num.find(' ')==string::npos)
        {
            for(int i=0;i<13;i++)
            {
                if(num==num1[i])
                {
                    cout<<i<<endl;
                    return;
                }
            }
            if(num=="tam")
            {
                cout<<"13"<<endl;
                return;
            }
            for(int i=1;i<13;i++)
            {
                if(num==num2[i])
                {
                    cout<<13*i<<endl;
                    return;
                }
            }
    
        }
        else
        {
            stringstream  ss(num);
            string temp2;
            ss>>temp2;
            string temp1;
            ss>>temp1;
           // cout<<temp2<<temp1;
            int a,b;
            for(int i=1;i<13;i++)
            {
                if(num2[i]==temp2)
                {
                    a=i;
                    break;
                }
            }
            for(int i=0;i<13;i++)
            {
                if(num1[i]==temp1)
                {
                    b=i;
                    break;
                }
            }
            cout<<13*a+b<<endl;
        }
    }
    
    
    int main()
    {
        int n;
        //cout<<num1[0];
        scanf("%d",&n);
        getchar();
        for(int i=0;i<n;i++)
        {
            string temp;
            getline(cin,temp);
            if(isdigit(temp[0]))
            {
                solve1(temp);
            }
            else
            {
                solve2(temp);
            }
        }
        return 0;
    }
     
  • 相关阅读:
    【Android】Android如何实现手机震动
    【Android】详解Android的menu菜单
    【Smali】Smali文件的动态调试
    【C#】C#项目如何获得项目的根目录
    【Android】Android如何对APK签名
    【Android】Android如何对APK反编译
    【SqlServer】在SqlServer中把数据导入导出为Excel文件
    【C#】解析C#中JSON.NET的使用
    【C#】浅析C#中的日期处理
    TCP与UDP传输协议
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10335802.html
Copyright © 2011-2022 走看看