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;
    }
     
  • 相关阅读:
    Server requested plaintext password but ‘client plaintext auth’ is disabled
    LDAP目录树中常见的关键字
    LINUX下让一个用户添加进多个组中
    CentOS5.6下samba+ldap+smbldaptools的安装
    解决configure: error: Cannot find pam headers. Please check if your system is ready for pam module development
    解决configure: error: C++ compiler cannot create executables问题
    IE中拖动DOM元素的例子
    请确保此代码文件中定义的类与“inherits”属性匹配,并且该类扩展的基类(例如Page 或UserControl)是正确的。
    DOM中的高级事件处理
    好导网(推荐)
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10335802.html
Copyright © 2011-2022 走看看