标签:earth har specific its 数字 type enter pre base
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.
Each input file contains one test case. For each case, the first line contains a positive integer N (<). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.
For each number, print in a line the corresponding number in the other language.
4
29
5
elo nov
tam
hel mar
may
115
13
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<string> vec2 = {"tret","jan","feb","mar","apr","may","jun","jly","aug" ,"sep","oct","nov","dec"}; vector<string> vec1 = {"","tam","hel","maa","huh","tou","kes" ,"hei","elo","syy","lok","mer","jou"}; int to_int(string s){ int sum = 0; for(int i=0;i < s.size();i++){ sum = sum*10 + (s[i]-‘0‘); } return sum; } int main(){ map<string,int> mp; for(int i=0;i <= 12;i++){ mp[vec2[i]] = i; } for(int i=13;i <= 24;i++){ mp[vec1[i-12]] = i; } int t; cin >> t;getchar(); while(t--){ string s; getline(cin,s); if(s[0] >= ‘0‘ && s[0] <= ‘9‘){ int num = to_int(s); if(num < 13) cout << vec2[num] << endl; else{ int shiwei = num/13; int gewei = num%13; if(gewei != 0) cout << vec1[shiwei] << " " << vec2[gewei] << endl; else cout << vec1[shiwei] << endl; } } else { if(s.size() < 5){ if(mp[s] < 13) cout << mp[s] << endl; else cout << (mp[s]-12)*13 << endl; } else{ string s1 = s.substr(0,3); string s2 = s.substr(4,3); cout << (mp[s1]-12)*13+mp[s2] << endl; } } } return 0; } //#include <iostream> //#include <string> //using namespace std; //string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; //string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; //string s; //int len; //void func1(int t) { // if (t / 13) cout << b[t / 13]; // if ((t / 13) && (t % 13)) cout << " "; // if (t % 13 || t == 0) cout << a[t % 13]; //} //void func2() { // int t1 = 0, t2 = 0; // string s1 = s.substr(0, 3), s2; // if (len > 4) s2 = s.substr(4, 3); // for (int j = 1; j <= 12; j++) { // if (s1 == a[j] || s2 == a[j]) t2 = j; // if (s1 == b[j]) t1 = j; // } // cout << t1 * 13 + t2; //} //int main() { //// int n; //// cin >> n; //// getchar(); // freopen("a","r",stdin); // for (int i = 0; i < 168; i++) { // s = to_string(i); // len = s.length(); // if (s[0] >= ‘0‘ && s[0] <= ‘9‘) // func1(stoi(s)); // else // func2(); // cout << endl; // } // return 0; //}
就是整除位都是单个字符串,在字符串变数字的时候没有考虑到。。
标签:earth har specific its 数字 type enter pre base
原文地址:https://www.cnblogs.com/cunyusup/p/10798597.html