1100. Mars Numbers (20)

缺乏、安全感 2022-05-28 06:41 227阅读 0赞

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:

  1. 4
  2. 29
  3. 5
  4. elo nov
  5. tam

Sample Output:

  1. hel mar
  2. may
  3. 115
  4. 13

题目大意:

代码:

  1. #include<stdio.h>
  2. #include<map>
  3. #include<string>
  4. #include<stdlib.h>
  5. #include<string.h>
  6. using namespace std;
  7. map<string,int> Map1;
  8. map<string,int> Map2;
  9. void init()
  10. {
  11. Map1["tret"]=0;
  12. Map1["jan"]=1;
  13. Map1["feb"]=2;
  14. Map1["mar"]=3;
  15. Map1["apr"]=4;
  16. Map1["may"]=5;
  17. Map1["jun"]=6;
  18. Map1["jly"]=7;
  19. Map1["aug"]=8;
  20. Map1["sep"]=9;
  21. Map1["oct"]=10;
  22. Map1["nov"]=11;
  23. Map1["dec"]=12;
  24. Map2["tam"]=1;
  25. Map2["hel"]=2;
  26. Map2["maa"]=3;
  27. Map2["huh"]=4;
  28. Map2["tou"]=5;
  29. Map2["kes"]=6;
  30. Map2["hei"]=7;
  31. Map2["elo"]=8;
  32. Map2["syy"]=9;
  33. Map2["lok"]=10;
  34. Map2["mer"]=11;
  35. Map2["jou"]=12;
  36. }
  37. int main()
  38. {
  39. int i,j,n,m,k,t,l;
  40. char str1[5],str2[5],str[10];
  41. scanf("%d",&n);
  42. init();
  43. getchar();
  44. for(l=0;l<n;l++)
  45. {
  46. gets(str);
  47. strcpy(str2,"");
  48. //printf("%s\n",str);
  49. for(i=0;str[i]!='\0';i++)
  50. {
  51. if(str[i]==' ')
  52. {
  53. for(j=0;j<i;j++)
  54. {
  55. str1[j]=str[j];
  56. }
  57. str1[j]='\0';
  58. t=0;
  59. for(j=i+1;str[j]!='\0';j++)
  60. {
  61. str2[t++]=str[j];
  62. }
  63. str2[t]='\0';
  64. break;
  65. }
  66. }
  67. if(str[i]=='\0')
  68. {
  69. strcpy(str1,str);
  70. }
  71. //printf("%s\n",str1);
  72. if(str1[0]>='0'&&str1[0]<='9')
  73. {
  74. map<string,int>::iterator it;
  75. m=atoi(str1);
  76. if(m/13!=0)
  77. {
  78. for(it=Map2.begin();it!=Map2.end();it++)
  79. {
  80. if(it->second==(m/13))
  81. {
  82. if(m%13!=0)
  83. printf("%s",(it->first).c_str());
  84. else
  85. printf("%s\n",(it->first).c_str());
  86. break;
  87. }
  88. }
  89. if(m%13!=0)
  90. {
  91. for(it=Map1.begin();it!=Map1.end();it++)
  92. {
  93. if(it->second==(m%13))
  94. {
  95. if(m/13!=0)
  96. printf(" %s\n",(it->first).c_str());
  97. else
  98. printf("%s\n",(it->first).c_str());
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. else
  105. {
  106. for(it=Map1.begin();it!=Map1.end();it++)
  107. {
  108. if(it->second==(m%13))
  109. {
  110. printf("%s\n",(it->first).c_str());
  111. break;
  112. }
  113. }
  114. }
  115. }
  116. else
  117. {
  118. if(Map2.find(str1)!=Map2.end())
  119. {
  120. k=0;
  121. k+=Map2[str1];
  122. k*=13;
  123. if(strlen(str2)!=0)
  124. {
  125. k+=Map1[str2];
  126. }
  127. printf("%d\n",k);
  128. }
  129. else
  130. {
  131. printf("%d\n",Map1[str1]);
  132. }
  133. }
  134. }
  135. return 0;
  136. }

发表评论

表情:
评论列表 (有 0 条评论,227人围观)

还没有评论,来说两句吧...

相关阅读

    相关 1100 校庆

    2019 年浙江大学将要庆祝成立 122 周年。为了准备校庆,校友会收集了所有校友的身份证号。现在需要请你编写程序,根据来参加校庆的所有人士的身份证号,统计来了多少校友。

    相关 TJU1100

    问题的本质是对于4个数组,每一个数组求一个分拆使两部分差最小。典型的DP。不过当时做的时候DP还学得不咋地,所以还是用搜索的办法~~还好也ac了 ![None.gif]