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 }
  • 相关阅读:
    springcloud系列五 feign远程调用服务
    ribbon负载均衡
    使用RestTemplate时报错java.lang.IllegalStateException: No instances available for 127.0.0.1
    HBase介绍
    HBase单机模式安装
    HDFS介绍及简单操作
    zookeeper三种模式安装详解(centos 7+zookeeper-3.4.9)
    zookeeper介绍
    hadoop搭建伪分布式集群(centos7+hadoop-3.1.0/2.7.7)
    linux配置本地yum源
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4842494.html
Copyright © 2011-2022 走看看