Skip to content

Instantly share code, notes, and snippets.

@prehistoricpenguin
Created September 8, 2014 13:11
Show Gist options
  • Save prehistoricpenguin/7c9048ec0c27820ca3b6 to your computer and use it in GitHub Desktop.
Save prehistoricpenguin/7c9048ec0c27820ca3b6 to your computer and use it in GitHub Desktop.
// 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