代码先锋网 代码片段及技术文章聚合

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

题目大意:


代码:

#include<stdio.h>
#include<map>
#include<string>
#include<stdlib.h>
#include<string.h>
using namespace std;
map<string,int> Map1;
map<string,int> Map2;
void init()
{
  Map1["tret"]=0;
  Map1["jan"]=1;
  Map1["feb"]=2;
  Map1["mar"]=3;
  Map1["apr"]=4;
  Map1["may"]=5;
  Map1["jun"]=6;
  Map1["jly"]=7;
  Map1["aug"]=8;
  Map1["sep"]=9;
  Map1["oct"]=10;
  Map1["nov"]=11;
  Map1["dec"]=12;
  Map2["tam"]=1;
  Map2["hel"]=2;
  Map2["maa"]=3;
  Map2["huh"]=4;
  Map2["tou"]=5;
  Map2["kes"]=6;
  Map2["hei"]=7;
  Map2["elo"]=8;
  Map2["syy"]=9;
  Map2["lok"]=10;
  Map2["mer"]=11;
  Map2["jou"]=12;
}
int main()
{
    int i,j,n,m,k,t,l;
    char str1[5],str2[5],str[10];
    scanf("%d",&n);
    init();
    getchar();
    for(l=0;l<n;l++)
    {
        gets(str);
        strcpy(str2,"");
        //printf("%s\n",str);
        for(i=0;str[i]!='\0';i++)
    {
        if(str[i]==' ')
        {
            for(j=0;j<i;j++)
            {
                str1[j]=str[j];
            }
            str1[j]='\0';
            t=0;
            for(j=i+1;str[j]!='\0';j++)
            {
                str2[t++]=str[j];
            }
            str2[t]='\0';
            break;
        }
    }
    if(str[i]=='\0')
    {
       strcpy(str1,str);
    }
    //printf("%s\n",str1);
        if(str1[0]>='0'&&str1[0]<='9')
        {
            map<string,int>::iterator it;
            m=atoi(str1);
            if(m/13!=0)
            {
                for(it=Map2.begin();it!=Map2.end();it++)
                {
                    if(it->second==(m/13))
                    {
                        if(m%13!=0)
                        printf("%s",(it->first).c_str());
                        else
                        printf("%s\n",(it->first).c_str());
                        break;
                    }
                }
                if(m%13!=0)
                {
                    for(it=Map1.begin();it!=Map1.end();it++)
                {
                    if(it->second==(m%13))
                    {
                        if(m/13!=0)
                        printf(" %s\n",(it->first).c_str());
                        else
                        printf("%s\n",(it->first).c_str());
                        break;
                    }
                }
                }

            }
            else
            {
                for(it=Map1.begin();it!=Map1.end();it++)
                {
                    if(it->second==(m%13))
                    {
                        printf("%s\n",(it->first).c_str());
                        break;
                    }
                }
            }
        }
        else
        {
            if(Map2.find(str1)!=Map2.end())
            {
                k=0;
                k+=Map2[str1];
                k*=13;
                if(strlen(str2)!=0)
                {
                   k+=Map1[str2];
                }
                printf("%d\n",k);
            }
            else
            {
               printf("%d\n",Map1[str1]);
            }
        }
    }
    return 0;
}

版权声明:本文为guoqingshuang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/guoqingshuang/article/details/79767400

智能推荐

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, d...

1100. Mars Numbers (20)

1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. The numbe...

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...

猜你喜欢

PAT (Advanced) 1100. Mars Numbers (20)

原题:1100. Mars Numbers (20) 解题思路; 按题意模拟即可。 代码如下:...

PAT 甲级 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, d...

Pat(A) 1100. Mars Numbers (20)

原题目: 原题链接:https://www.patest.cn/contests/pat-a-practise/1100 1100. Mars Numbers (20) People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 ...

1100. Mars Numbers (20)<map>

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, d...

PAT A 1100. Mars Numbers (20)

对于13,26这种数,只应该输出“tam”和“hel”,不应该输出“tam tret”和“hel tret”。...