1.题面
https://www.patest.cn/contests/pat-a-practise/1100
2.题意
简单的进制转化题
3.思路
需要注意输入为13的倍数时不需要输出个位
4.代码
/***************************************************************** > File Name: cpp_acm.cpp > Author: Uncle_Sugar > Mail: [email protected] > Created Time: Thu 02 Feb 2017 14:56:53 CST *****************************************************************/ # include <cstdio> # include <cstring> # include <cctype> # include <cmath> # include <cstdlib> # include <climits> # include <iostream> # include <iomanip> # include <set> # include <map> # include <vector> # include <stack> # include <queue> # include <algorithm> using namespace std; template<class T>void PrintArray(T* first,T* last,char delim=' '){ for (;first!=last;first++) cout << *first << (first+1==last?'\n':delim); } /* 1.see the size of the input data before you select your algorithm 2.cin&cout is not recommended in ACM/ICPC 3.pay attention to the size you defined, for instance the size of edge is double the size of vertex */ const int debug = 1; // const int size = 10 + ; const int INF = INT_MAX>>1; typedef long long ll; const char * marnum[13] = { "tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" }; const char * earnum[13] = { "zero", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" }; int main() { // std::ios::sync_with_stdio(false);cin.tie(0); const int size = 10000; map<string, int> marmp; map<string, int> earmp; for (int i = 0; i < 13; i++) marmp[marnum[i]] = i; for (int i = 0; i < 13; i++) earmp[earnum[i]] = i; int n; scanf("%d", &n); getchar(); while (n--){ char str[size]; gets(str); if (isdigit(str[0])){ int t = atoi(str); int len = 0; if (t == 0){ printf("tret\n"); }else { if (t%13 == 0) printf("%s\n", marnum[t/13]); else if (t > 13) printf("%s %s\n", marnum[t/13], earnum[t%13]); else printf("%s\n", earnum[t%13]); } }else { char ss[100]; char *p = strtok(str, " "); int num = 0; vector<string> vct; while (p){ sscanf(p, "%s", ss); vct.push_back(ss); p = strtok(NULL, " "); } for (int i = 0; i < vct.size(); i++) if (marmp.find(vct[i]) != marmp.end()) num += marmp[vct[i]]*13; else num += earmp[vct[i]]; cout << num << endl; } } return 0; }