标签:next getch ica standard 火星 == cin sub info
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
思路
进制转换和字符串处理。
1.分为地球数字转火星文、火星文转地球数字两种情况。
2.火星文转地球数字分为三种情况:1)单独一个火星数字 2)两个火星数字(第二个火星数字不是tret) 3)两个火星数字(第二个火星数字一定是tret(零))。
代码
#include<iostream> #include<vector> #include<string> using namespace std; vector<string> num = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"}; vector<string> highernum = {"sb","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok","mer", "jou"}; int search(string s) { for(int i = 0;i < num.size();i++) { if(s == num[i]) return i; } for(int i = 0;i < highernum.size();i++) { if(s == highernum[i]) return -i; } return 0; } int main() { int N; scanf("%d",&N); getchar(); while(N--) { string number; getline(cin,number); if(number[0] <= ‘9‘) { int n = stoi(number); int first = n/13,second = n % 13; if(n == 0) cout << num[n] <<endl; else { if(first !=0 && second != 0) cout << highernum[first]<< " " <<num[second] << endl; else if(first != 0) cout << highernum[first] << endl; else if(second != 0) cout << num[second] << endl; } } else if(number.size() == 3) { int res = search(number); if(res >= 0) cout << res <<endl; else cout << -res * 13 << endl; } else if(number.size() == 7) { string fst = number.substr(0,3); string sec = number.substr(4,3); cout << -search(fst) * 13 + search(sec) << endl; } else { string fst = number.substr(0,3); cout << -search(fst) * 13 << endl; } } }
标签:next getch ica standard 火星 == cin sub info
原文地址:http://www.cnblogs.com/0kk470/p/7646783.html