zoukankan      html  css  js  c++  java
  • pat1100. 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 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
    

    进制转换。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<stack>
     5 #include<set>
     6 #include<map>
     7 #include<queue>
     8 #include<algorithm>
     9 using namespace std;
    10 string dight[2][13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec",
    11                      "tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
    12 int main(){
    13     //freopen("D:\INPUT.txt","r",stdin);
    14     int n,num;
    15     string s;
    16     scanf("%d",&n);
    17     while(n--){
    18         cin>>s;
    19         int i,j;
    20         num=0;
    21         if(s[0]>='0'&&s[0]<='9'){
    22             for(i=0;i<s.length();i++){
    23                 num*=10;
    24                 num+=s[i]-'0';
    25             }
    26             if(num>12){
    27                 cout<<dight[1][num/13];
    28                 num%=13;
    29                 if(num){
    30                     cout<<" "<<dight[0][num];
    31                 }
    32                 cout<<endl;
    33             }
    34             else{
    35                 cout<<dight[0][num]<<endl;
    36             }
    37         }
    38         else{
    39             for(i=0;i<13;i++){
    40                 if(dight[1][i]==s){
    41                     break;
    42                 }
    43             }
    44             if(i!=13){
    45                 num+=13*i;
    46                 if(getchar()==' '){
    47                     cin>>s;
    48                     for(i=0;i<13;i++){
    49                         if(dight[0][i]==s){
    50                             break;
    51                         }
    52                     }
    53                     num+=i;
    54                 }
    55             }
    56             else{
    57                 for(i=0;i<13;i++){
    58                     if(dight[0][i]==s){
    59                         break;
    60                     }
    61                 }
    62                 num+=i;
    63             }
    64             printf("%d
    ",num);
    65         }
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    新一篇: 正则表达式使用详解
    C#預處理指令
    [转]SQL Server 2005 Beta 2 TransactSQL 增强功能
    SQL Server 2005之PIVOT/UNPIVOT行列转换
    爬虫入门到放弃系列01:什么是爬虫
    我的程序员之路01:自学Java篇
    Java入门者:如何写出美观的Java代码?
    JedisCluster使用pipeline操作Redis Cluster最详细从0到1实现过程
    IDEA超神之路:安装、运行HelloWorld以及激活到2099年的第一场雪
    软考系统架构师、信息系统项目管理师、系统分析师、系统规划与管理师和网络规划师资料大汇总
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4842494.html
Copyright © 2011-2022 走看看