C++ 代码
#include <iostream>
using namespace std;
int T;
string s, p;
string m[10] = {"double ", "triple ", "quadruple ", "quintuple ", "sextuple ", "septuple ", "octuple ", "nonuple ", "decuple "};
string q[10] = {"zero ", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine "};
string work(int l, int r){
string res;
int cnt = 0;
char tmp = '.';
for(int i = l; i < r; ++ i){
if(s[i] == tmp){
++ cnt;
}else{
if(cnt == 0){
tmp = s[i];
cnt = 1;
}else{
if(cnt > 10){
while(cnt --)
res += q[tmp - '0'];
}
else if(cnt == 1)
res += q[tmp - '0'];
else
res = res + m[cnt - 2] + q[tmp - '0'];
tmp = s[i];
cnt = 1;
}
}
}
if(cnt > 10) while(cnt --) res += q[tmp - '0'];
else if(cnt >= 2) res = res + m[cnt - 2] + q[tmp - '0'];
else res += q[tmp - '0'];
return res;
}
int main()
{
cin >> T;
for(int i = 1; i <= T; ++ i){
cin >> s >> p;
string ret;
int cnt = 0, j = 0;
for(char c : p){
if(c == '-') {
ret += work(j, j + cnt);
j = j + cnt;
cnt = 0;
}else{
cnt = cnt * 10 + (c - '0');
}
}
ret += work(j, j + cnt);
printf("Case #%d: %s\n", i, ret.c_str());
}
return 0;
}