码迷,mamicode.com
首页 > 其他好文 > 详细

1100. Mars Numbers (20)

时间:2015-12-06 13:02:52      阅读:195      评论:0      收藏: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:
4
29
5
elo nov
tam
Sample Output:
hel mar
may
115
13

 

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <memory>
  5. #include <string.h>
  6. #pragma warning(disable:4996)
  7. using namespace std;
  8. string gewei[12] = { "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
  9. string shiwei[12] = { "tam", "hel", "maa", "huh", "tou", "kes", "hei","elo", "syy", "lok", "mer", "jou" };
  10. int main(void) {
  11. int n;
  12. // cin >> n;
  13. scanf("%d\n", &n);
  14. string s="";
  15. for (int i = 0; i < n; i++) {
  16. s = "";
  17. //cin >> s;
  18. char a[10];
  19. memset(a, 0, sizeof(a));
  20. int k = 0;
  21. while (1) {
  22. scanf("%c", &a[k]);
  23. if (a[k] != ‘\n‘) {
  24. s += a[k];
  25. k++;
  26. }
  27. else {
  28. break;
  29. }
  30. }
  31. if (s[0] >= ‘0‘&&s[0] <= ‘9‘) {
  32. int num=0;
  33. for (int i = 0; i <= s.length() - 1; i++) {
  34. num = num * 10;
  35. num += s[i] - ‘0‘;
  36. }
  37. if (num < 13&&num>0) {
  38. cout << gewei[num-1] << endl;
  39. }
  40. else if (num != 0) {
  41. if (num % 13 != 0)
  42. cout << shiwei[num / 13 - 1] << " " << gewei[num % 13 - 1] << endl;
  43. else
  44. cout << shiwei[num / 13 - 1] << endl;
  45. }
  46. else
  47. cout << "tret" << endl;
  48. }
  49. else {
  50. int marsnum = 0;
  51. if (s.length() == 3) {
  52. for (int j = 0; j < 12; j++) {
  53. if (s == gewei[j]) {
  54. marsnum = j+1;
  55. break;
  56. }
  57. }
  58. for (int j = 0; j < 12; j++) {
  59. if (s == shiwei[j]) {
  60. marsnum = j*13+13;
  61. break;
  62. }
  63. }
  64. }
  65. else {
  66. string s1="", s2="";
  67. for (int j = 0; j < 3; j++)
  68. s1 += s[j];
  69. for (int j = 4; j < 7; j++)
  70. s2 += s[j];
  71. int gaowei = 0, diwei = 0;
  72. for (int j = 0; j < 12; j++) {
  73. if (s2 == gewei[j]) {
  74. diwei = j + 1;
  75. break;
  76. }
  77. }
  78. for (int j = 0; j < 12; j++) {
  79. if (s1 == shiwei[j]) {
  80. gaowei = j + 1;
  81. break;
  82. }
  83. }
  84. marsnum = gaowei * 13 + diwei;
  85. }
  86. cout << marsnum << endl;
  87. }
  88. }
  89. /*while (true)
  90. {
  91. }*/
  92. return 0;
  93. }

  1. #include <string>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #pragma warning(disable:4996)
  5. using namespace std;
  6. string diwei[13] = {"", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
  7. string gaowei[13] = { "", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok","mer", "jou" };
  8. int main(void) {
  9. int n;
  10. //cin >> n;
  11. scanf("%d", &n);
  12. char c;
  13. for (int i = 0; i < n; i++) {
  14. string s="";
  15. while (true)
  16. {
  17. scanf("%c", &c);
  18. if (c == ‘\n‘&&s.length()>0)
  19. break;
  20. else if(c!=‘\n‘)
  21. s += c;
  22. }
  23. if (s[0] >= ‘0‘&&s[0] <= ‘9‘) {
  24. int num=0;
  25. for (int i = 0; i < s.length(); i++)
  26. num = num * 10 + s[i] - ‘0‘;
  27. if (num == 0)
  28. cout << "tret" << endl;
  29. else if (num < 13)
  30. cout << diwei[num] << endl;
  31. else if (num % 13 == 0)
  32. cout << gaowei[num / 13] << endl;
  33. else
  34. cout << gaowei[num / 13] << " " << diwei[num % 13] << endl;
  35. }
  36. else {
  37. if (s.length() == 3) {
  38. for (int i = 0; i < 13; i++) {
  39. if (s == diwei[i])
  40. cout << i << endl;
  41. if (s == gaowei[i])
  42. cout << 13 * i << endl;
  43. }
  44. }
  45. else if (s.length() == 4) {
  46. cout << "0" << endl;
  47. }
  48. else {
  49. string s1, s2;
  50. for (int i = 0; i < 3; i++) {
  51. s1 += s[i];
  52. s2 += s[i + 4];
  53. }
  54. int mnum=0;
  55. for (int i = 0; i < 13; i++) {
  56. if (diwei[i] == s2)
  57. mnum += i;
  58. if (gaowei[i] == s1)
  59. mnum += 13 * i;
  60. }
  61. cout << mnum << endl;
  62. }
  63. }
  64. }
  65. }





1100. Mars Numbers (20)

标签:

原文地址:http://www.cnblogs.com/zzandliz/p/5023351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!