Created
September 8, 2014 13:11
-
-
Save prehistoricpenguin/7c9048ec0c27820ca3b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://pat.zju.edu.cn/contests/pat-a-practise/1005 | |
#include <algorithm> | |
#include <string> | |
#include <cstdio> | |
#include <cassert> | |
#include <cstring> | |
#include <cstdlib> | |
using namespace std; | |
const char* tbl[] = { | |
"zero", "one", "two", | |
"three", "four", "five", | |
"six", "seven", "eight", | |
"nine" | |
}; | |
int main() { | |
const int klen = 105; | |
char str[klen]; | |
scanf("%s", str); | |
int len = strlen(str); | |
int sum = std::accumulate(str, str + len, 0, | |
[](int init, char ch) { | |
return init + ch - '0'; | |
}); | |
char ans[klen]; | |
len = sprintf(ans, "%d", sum); | |
for (int i = 0; i < len; ++i) { | |
printf("%s%s", tbl[ans[i] - '0'], i == len - 1 ? "\n": " "); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment