PAT-1100(Mars Numbers)
题目见这里
题目并不难,不过一开始我没能理清题意,参考了下这里,明白题目实际是考进制转换(13进制),外加一个映射(hash),这当然比较简单啦!需要注意的是,样例中tam(Mars Number)----->13(Earth),由此可知,以13的整倍数(Earth)出现时,不带‘tret’ (earth:0)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <cstdio> #include <iostream> #include <map> #include <cstring> using namespace std; struct ptrCmp{ bool operator ()( const char *s1, const char *s2) const { return strcmp(s1,s2)<0; } }; int main(){ const char hash[25][5]={ "tret" , "jan" , "feb" , "mar" , "apr" , "may" , "jun" , "jly" , "aug" , "sep" , "oct" , "nov" , "dec" , "tam" , "hel" , "maa" , "huh" , "tou" , "kes" , "hei" , "elo" , "syy" , "lok" , "mer" , "jou" }; map< const char *, int ,ptrCmp>hash1; int i; for (i=0;i<25;i++) hash1.insert(pair< const char *, int >(hash[i],i)); // freopen("Data.txt","r",stdin); char s[5],s1[5],c; int n; scanf( "%d" ,&n); getchar(); while (n--){ scanf( "%s" ,s); scanf( "%c" ,&c); if (c== ' ' || (s[0]>= 'a' && s[0]<= 'z' )){ if (c== ' ' ) scanf( "%s" ,s1); if (c== '\n' ){ int index = hash1[s]; if (index<13) printf( "%d" ,index); else printf( "%d" ,(index-12)*13); } else printf( "%d" ,(hash1[s]-12)*13+hash1[s1]); printf( "\n" ); } else { int key,k; key=0,k=0; while (s[k]) key = 10*key+s[k]- '0' , k ++; if (key<13) printf( "%s\n" ,hash[key]); else { printf( "%s" ,hash[key/13+12]); if (key%13) printf( " %s" ,hash[key%13]); //不带'tret' printf( "\n" ); } } } return 0; } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步