People on Mars count their numbers with base 13:
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 tamSample Output:
hel mar may 115 13
#include <iostream>#include <stdio.h>#include <string>#include <memory>#include <string.h>#pragma warning(disable:4996)using namespace std;string gewei[12] = { "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };string shiwei[12] = { "tam", "hel", "maa", "huh", "tou", "kes", "hei","elo", "syy", "lok", "mer", "jou" };int main(void) {int n;// cin >> n;scanf("%d\n", &n);string s="";for (int i = 0; i < n; i++) {s = "";//cin >> s;char a[10];memset(a, 0, sizeof(a));int k = 0;while (1) {scanf("%c", &a[k]);if (a[k] != ‘\n‘) {s += a[k];k++;}else {break;}}if (s[0] >= ‘0‘&&s[0] <= ‘9‘) {int num=0;for (int i = 0; i <= s.length() - 1; i++) {num = num * 10;num += s[i] - ‘0‘;}if (num < 13&&num>0) {cout << gewei[num-1] << endl;}else if (num != 0) {if (num % 13 != 0)cout << shiwei[num / 13 - 1] << " " << gewei[num % 13 - 1] << endl;elsecout << shiwei[num / 13 - 1] << endl;}elsecout << "tret" << endl;}else {int marsnum = 0;if (s.length() == 3) {for (int j = 0; j < 12; j++) {if (s == gewei[j]) {marsnum = j+1;break;}}for (int j = 0; j < 12; j++) {if (s == shiwei[j]) {marsnum = j*13+13;break;}}}else {string s1="", s2="";for (int j = 0; j < 3; j++)s1 += s[j];for (int j = 4; j < 7; j++)s2 += s[j];int gaowei = 0, diwei = 0;for (int j = 0; j < 12; j++) {if (s2 == gewei[j]) {diwei = j + 1;break;}}for (int j = 0; j < 12; j++) {if (s1 == shiwei[j]) {gaowei = j + 1;break;}}marsnum = gaowei * 13 + diwei;}cout << marsnum << endl;}}/*while (true){}*/return 0;}
#include <string>#include <iostream>#include <stdio.h>#pragma warning(disable:4996)using namespace std;string diwei[13] = {"", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };string gaowei[13] = { "", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok","mer", "jou" };int main(void) {int n;//cin >> n;scanf("%d", &n);char c;for (int i = 0; i < n; i++) {string s="";while (true){scanf("%c", &c);if (c == ‘\n‘&&s.length()>0)break;else if(c!=‘\n‘)s += c;}if (s[0] >= ‘0‘&&s[0] <= ‘9‘) {int num=0;for (int i = 0; i < s.length(); i++)num = num * 10 + s[i] - ‘0‘;if (num == 0)cout << "tret" << endl;else if (num < 13)cout << diwei[num] << endl;else if (num % 13 == 0)cout << gaowei[num / 13] << endl;elsecout << gaowei[num / 13] << " " << diwei[num % 13] << endl;}else {if (s.length() == 3) {for (int i = 0; i < 13; i++) {if (s == diwei[i])cout << i << endl;if (s == gaowei[i])cout << 13 * i << endl;}}else if (s.length() == 4) {cout << "0" << endl;}else {string s1, s2;for (int i = 0; i < 3; i++) {s1 += s[i];s2 += s[i + 4];}int mnum=0;for (int i = 0; i < 13; i++) {if (diwei[i] == s2)mnum += i;if (gaowei[i] == s1)mnum += 13 * i;}cout << mnum << endl;}}}}
原文:http://www.cnblogs.com/zzandliz/p/5023351.html