zoukankan      html  css  js  c++  java
  • PAT 1044. 火星数字(20)

    火星人是以13进制计数的:

    • 地球人的0被火星人称为tret。
    • 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
    • 火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

    例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

    输入格式:

    输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。

    输出格式:

    对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

    输入样例:

    4
    29
    5
    elo nov
    tam
    

    输出样例:

    hel mar
    may
    115
    13
    需注意十位有数字而个位是零的情况,只输出十位数字。
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 #include<ctype.h>
     5 #include<math.h>
     6 
     7 int main(){
     8     char low[13][5]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
     9     char up[13][5]={" ","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    10     char temp[10];
    11     int temp1;
    12     int n;
    13     scanf("%d",&n);
    14     getchar(); 
    15     for(int i=0;i<n;i++){
    16         gets(temp);
    17         if(temp[0]>='0'&&temp[0]<='9'){
    18             int a = atoi(temp);
    19             if(a/13!=0){
    20                 if(a%13){
    21                     printf("%s ",up[a/13]);
    22                     printf("%s
    ",low[a%13]);
    23                 }
    24                 else
    25                     printf("%s
    ",up[a/13]);
    26             }
    27             else    
    28                 printf("%s
    ",low[a%13]);
    29         }    
    30         else{
    31             temp1 = 0;
    32             char *result = strtok(temp," "); 
    33             for(int j=0;j<13;j++){
    34                 if(strcmp(up[j],result)==0){
    35                     temp1 = temp1+j*13;
    36                 }
    37             }
    38             for(int j=0;j<13;j++){
    39                 if(strcmp(low[j],result)==0){
    40                     temp1 = temp1+j;
    41                 }
    42             }
    43             result = strtok(NULL," ");
    44             if(result!=NULL){
    45                 for(int j=0;j<13;j++){
    46                     if(strcmp(low[j],result)==0){
    47                         temp1 = temp1+j;
    48                     }
    49                 }
    50             }
    51             printf("%d
    ",temp1);
    52         }
    53         
    54     } 
    55 } 
  • 相关阅读:
    3D流水线
    log4cplus 配置文件的编写
    linux下的log4cplus的安装和使用
    日志信息的编写与调用
    转C++内存池实现
    转:自定义内存池的使用
    在linux查看内存的大小
    转:C++内存池
    数组指针 和指针数组的区别
    new的三种形态
  • 原文地址:https://www.cnblogs.com/lolybj/p/6238503.html
Copyright © 2011-2022 走看看