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;
    }
     
  • 相关阅读:
    阿里云服务器CentOS系统putty登录安全组设置
    5!(简单的了解for循环与递归的区别)
    一个简单的九九乘法表的打印输出,对for循环的认识
    6.SpringCloud学习(六)——Spring Cloud Bus 消息总线
    5.SpringCloud学习(五)——Spring Cloud Config 配置中心
    3.SpringCloud学习(三)——Spring Cloud Hystrix 服务降级
    2.SpringCloud学习(二)——Spring Cloud Eureka 服务注册中心
    1.SpringCloud学习(一)——Spring Cloud Ribbon 实现负载均衡
    17.SpringBoot学习(十七)——Spring Boot 自定义Starter
    16.SpringBoot学习(十六)——Spring Boot MessageConverter消息转换器
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10335802.html
Copyright © 2011-2022 走看看