• 1044 火星数字


    火星人是以 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
    
     
    思路:这题用map做会简单很多,主要考察进制转换,这里有两种解法,推荐解法一......
     
     1 /*1044火星数字  解法一 
     2    tret 0 , jan 1, feb 2, mar 3, apr 4, may 5, jun 6,
     3     jly 7, aug 8, sep 9, oct 10, nov 11, dec 12  个位
     4     tam 1, hel 2, maa 3, huh 4, tou 5, kes 6, 
     5     hei 7, elo 8, syy 9, lok 10, mer 11, jou 12  十位  */
     6 #include<iostream>
     7 #include<cstring>
     8 #include<cmath>
     9 #include<algorithm>
    10 #include<map>
    11 using namespace std;
    12 int main()
    13 {
    14     string diwei[13]={"tret","jan","feb","mar", "apr", "may",
    15                     "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    16     string gaowei[13]={"#","tam","hel", "maa", "huh", "tou", "kes", "hei",
    17                    "elo", "syy", "lok", "mer", "jou"};//忽略高位的0 
    18     map<int,string>earth_mars1;
    19     map<int,string>earth_mars2;
    20     map<string,int>mars_earth1;
    21     map<string,int>mars_earth2;
    22     for(int i=0;i<13;i++)
    23     {
    24         earth_mars1[i]=diwei[i];
    25         earth_mars2[i]=gaowei[i];
    26         mars_earth1[diwei[i]]=i;
    27         mars_earth2[gaowei[i]]=i;
    28     }
    29     int T;
    30     cin>>T;
    31     getchar();
    32     while(T--)
    33     {
    34         char ch;
    35         string str1,str2;
    36         int count=0,flag;
    37         cin>>str1;
    38         ch=getchar();
    39         if(ch!='
    ')
    40         cin>>str2;
    41         if(str1[0]>='0'&&str1[0]<='9')
    42         flag=0;//地球转火星
    43         else
    44         flag=1;//火星转地球
    45         
    46         
    47         if(flag==0)//只有str1 
    48         {
    49             int num=stoi(str1);
    50             int shiwei=num/13;
    51             int gewei=num%13;
    52             if(shiwei!=0&&gewei!=0)
    53                 cout<<earth_mars2[shiwei]<<" "<<earth_mars1[gewei]<<endl;
    54             else if(shiwei==0)
    55                 cout<<earth_mars1[gewei]<<endl;
    56             else if(gewei==0)
    57                 cout<<earth_mars2[shiwei]<<endl;
    58         }
    59         
    60         
    61         else if(flag==1)//可能有str2 
    62         {
    63             if(str2=="")//无str2
    64             {
    65                 if(mars_earth1[str1]!=0)
    66                     cout<<mars_earth1[str1]<<endl;
    67                 else if(mars_earth1[str1]==0)//str1是高位 
    68                     cout<<mars_earth2[str1]*13<<endl;
    69              }
    70             else
    71             {
    72                 cout<<mars_earth2[str1]*13+mars_earth1[str2]<<endl;
    73             }
    74         }
    75     }
    76     return 0;
    77 }
      1 /*1044火星数字   解法二
      2    tret 0 , jan 1, feb 2, mar 3, apr 4, may 5, jun 6, jly 7, aug 8, sep 9, oct 10, nov 11, dec 12  个位
      3             tam 1, hel 2, maa 3, huh 4, tou 5, kes 6, hei 7, elo 8, syy 9, lok 10, mer 11, jou 12  十位  */
      4 #include<stdio.h>
      5 #include<math.h>
      6 #include<string.h>
      7 #include<stdlib.h>
      8 #include<ctype.h>
      9 int main()
     10 {
     11     int n;
     12     scanf("%d
    ",&n);
     13     char num[20];
     14     int flag;
     15     for(int i=0;i<n;i++)
     16     {
     17         gets(num);
     18         if(num[0]>='0'&&num[0]<='9')
     19             flag=1;//地球转火星
     20         else
     21             flag=0;//火星转地球 
     22         if(flag==1)
     23         {
     24             int shu=atoi(num);//字符串转数字 
     25             if(shu<13)
     26             {
     27                 if(shu==0)  printf("tret
    ");
     28                 else if(shu==1) printf("jan
    ");
     29                 else if(shu==2) printf("feb
    ");
     30                 else if(shu==3) printf("mar
    ");
     31                 else if(shu==4) printf("apr
    ");
     32                 else if(shu==5) printf("may
    ");
     33                 else if(shu==6) printf("jun
    ");
     34                 else if(shu==7) printf("jly
    ");
     35                 else if(shu==8) printf("aug
    ");
     36                 else if(shu==9) printf("sep
    ");
     37                 else if(shu==10) printf("oct
    ");
     38                 else if(shu==11) printf("nov
    ");
     39                 else if(shu==12) printf("dec
    ");
     40             }
     41             else if(shu>=13)
     42             {
     43                 int ge=shu%13;
     44                 int shi=shu/13;
     45                 if(ge==0)
     46                 {
     47                     if(shi==1) printf("tam
    ");
     48                     else if(shi==2) printf("hel
    ");
     49                     else if(shi==3) printf("maa
    ");
     50                     else if(shi==4) printf("huh
    ");
     51                     else if(shi==5) printf("tou
    ");
     52                     else if(shi==6) printf("kes
    ");
     53                     else if(shi==7) printf("hei
    ");
     54                     else if(shi==8) printf("elo
    ");
     55                     else if(shi==9) printf("syy
    ");
     56                     else if(shi==10) printf("lok
    ");
     57                     else if(shi==11) printf("mer
    ");
     58                     else if(shi==12) printf("jou
    ");
     59                 }
     60                 else 
     61                 {
     62                     if(shi==1) printf("tam ");
     63                     else if(shi==2) printf("hel ");
     64                     else if(shi==3) printf("maa ");
     65                     else if(shi==4) printf("huh ");
     66                     else if(shi==5) printf("tou ");
     67                     else if(shi==6) printf("kes ");
     68                     else if(shi==7) printf("hei ");
     69                     else if(shi==8) printf("elo ");
     70                     else if(shi==9) printf("syy ");
     71                     else if(shi==10) printf("lok ");
     72                     else if(shi==11) printf("mer ");
     73                     else if(shi==12) printf("jou ");
     74                 
     75                     if(ge==1) printf("jan
    ");
     76                     else if(ge==2) printf("feb
    ");
     77                     else if(ge==3) printf("mar
    ");
     78                     else if(ge==4) printf("apr
    ");
     79                     else if(ge==5) printf("may
    ");
     80                     else if(ge==6) printf("jun
    ");
     81                     else if(ge==7) printf("jly
    ");
     82                     else if(ge==8) printf("aug
    ");
     83                     else if(ge==9) printf("sep
    ");
     84                     else if(ge==10) printf("oct
    ");
     85                     else if(ge==11) printf("nov
    ");
     86                     else if(ge==12) printf("dec
    ");
     87                 }
     88             }
     89         }
     90         else if(flag==0)
     91         {
     92             int len=strlen(num);
     93             int t=0;
     94             for(int i=0;i<len;i++)
     95             {
     96                 if(num[i]==' ')  
     97                     t++;
     98             }
     99             if(t==0)
    100             {
    101                 if(strcmp(num,"tret")==0) printf("0
    ");
    102                 else if(strcmp(num,"jan")==0) printf("1
    ");
    103                 else if(strcmp(num,"feb")==0) printf("2
    ");
    104                 else if(strcmp(num,"mar")==0) printf("3
    ");
    105                 else if(strcmp(num,"apr")==0) printf("4
    ");
    106                 else if(strcmp(num,"may")==0) printf("5
    ");
    107                 else if(strcmp(num,"jun")==0) printf("6
    ");
    108                 else if(strcmp(num,"jly")==0) printf("7
    ");
    109                 else if(strcmp(num,"aug")==0) printf("8
    ");
    110                 else if(strcmp(num,"sep")==0) printf("9
    ");
    111                 else if(strcmp(num,"oct")==0) printf("10
    ");
    112                 else if(strcmp(num,"nov")==0) printf("11
    ");
    113                 else if(strcmp(num,"dec")==0) printf("12
    ");
    114                 else if(strcmp(num,"tam")==0) printf("13
    ");
    115                 else if(strcmp(num,"hel")==0) printf("26
    ");
    116                 else if(strcmp(num,"maa")==0) printf("39
    ");
    117                 else if(strcmp(num,"huh")==0) printf("52
    ");
    118                 else if(strcmp(num,"tou")==0) printf("65
    ");
    119                 else if(strcmp(num,"kes")==0) printf("78
    ");
    120                 else if(strcmp(num,"hei")==0) printf("91
    ");
    121                 else if(strcmp(num,"elo")==0) printf("104
    ");
    122                 else if(strcmp(num,"syy")==0) printf("117
    ");
    123                 else if(strcmp(num,"lok")==0) printf("130
    ");
    124                 else if(strcmp(num,"mer")==0) printf("143
    ");
    125                 else if(strcmp(num,"jou")==0) printf("156
    ");    
    126             }
    127             else if(t==1)
    128             {
    129                 char shi1[5];
    130                 char ge1[5];
    131                 int flag1=0;
    132                 int t=0;
    133                 for(int i=0;i<len;i++)
    134                 {
    135                     if(flag1==0)
    136                     {
    137                         if(num[i]!=' ') 
    138                             shi1[i]=num[i];
    139                         else 
    140                         {
    141                           shi1[i]=''; 
    142                           flag1=1; 
    143                           continue;
    144                         }
    145                     }
    146                     else if(flag1==1)
    147                         ge1[t++]=num[i];
    148                 }    
    149                 ge1[t]='';
    150                 int sum=0;
    151                 if(strcmp(shi1,"tam")==0)     sum+=13*1;
    152                 else if(strcmp(shi1,"hel")==0) sum+=13*2;
    153                 else if(strcmp(shi1,"maa")==0) sum+=13*3;
    154                 else if(strcmp(shi1,"huh")==0) sum+=13*4;
    155                 else if(strcmp(shi1,"tou")==0) sum+=13*5;
    156                 else if(strcmp(shi1,"kes")==0) sum+=13*6;
    157                 else if(strcmp(shi1,"hei")==0) sum+=13*7;
    158                 else if(strcmp(shi1,"elo")==0) sum+=13*8;
    159                 else if(strcmp(shi1,"syy")==0) sum+=13*9;
    160                 else if(strcmp(shi1,"lok")==0) sum+=13*10;
    161                 else if(strcmp(shi1,"mer")==0) sum+=13*11;
    162                 else if(strcmp(shi1,"jou")==0) sum+=13*12;
    163                 if(strcmp(ge1,"jan")==0)     sum+=1;
    164                 else if(strcmp(ge1,"feb")==0) sum+=2;
    165                 else if(strcmp(ge1,"mar")==0) sum+=3;
    166                 else if(strcmp(ge1,"apr")==0) sum+=4;
    167                 else if(strcmp(ge1,"may")==0) sum+=5;
    168                 else if(strcmp(ge1,"jun")==0) sum+=6;
    169                 else if(strcmp(ge1,"jly")==0) sum+=7;
    170                 else if(strcmp(ge1,"aug")==0) sum+=8;
    171                 else if(strcmp(ge1,"sep")==0) sum+=9;
    172                 else if(strcmp(ge1,"oct")==0) sum+=10;
    173                 else if(strcmp(ge1,"nov")==0) sum+=11;
    174                 else if(strcmp(ge1,"dec")==0) sum+=12;
    175                 printf("%d
    ",sum);
    176             }
    177         }
    178     }
    179     return 0;
    180 } 
    大佬见笑,,
  • 相关阅读:
    获得指定目录路径
    播放音乐(mciSendString)
    INotifyPropertyChanged接口
    从excel表格加载数据返回DataSet
    事件与委托
    .net中实现伪静态的学习小结
    今天开通博客了
    EasyUI后台管理系统学习四
    EasyUI后台管理系统学习三
    EasyUI后台管理系统学习二
  • 原文地址:https://www.cnblogs.com/xwl3109377858/p/10475450.html
Copyright © 2020-2023  润新知