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;
    }
     
  • 相关阅读:
    python网络爬虫与信息提取——5.信息组织与提取方法
    python网络爬虫与信息提取——4.Beautiful Soup库入门
    python网络爬虫与信息提取——3.requests爬虫实战
    python网络爬虫与信息提取——2.网络爬虫排除标准robots
    python网络爬虫与信息提取——1.requests库入门
    时间戳转日期
    splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目
    数组、对象等的按值传递与数字、字符串不同
    用flex做垂直居中
    手机端页面自适应解决方案-rem布局
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10335802.html
Copyright © 2011-2022 走看看