PAT 1005. Spell It Right (20)

题目地址: http://www.patest.cn/contests/pat-a-practise/1005

太水了点

 1 #include<cstdio>

 2 #include<iostream>

 3 #include<sstream>

 4 

 5 using namespace std;

 6 

 7 const char *english[] = {

 8         "zero",

 9         "one",

10         "two",

11         "three",

12         "four",

13         "five",

14         "six",

15         "seven",

16         "eight",

17         "nine",

18         "ten"

19 };

20 

21 const int MAXN = 200;

22 char num[MAXN];

23 

24 int add(char *s) {

25         int result = 0;

26         while(*s) {

27                 result += *s - '0';

28                 ++s;

29         }

30         return result;

31 }

32 

33 void print(int n) {

34         stringstream ss;

35         ss << n;

36         string str = ss.str();

37         cout << english[str[0] - '0'];

38         for (int i = 1; i < str.size(); ++i) {

39                 cout << " " << english[str[i] - '0'];

40         }

41         cout << endl;

42 }

43 int main() {

44         while(cin >> num) {

45                 print(add(num));

46         }

47         return 0;

48 }

 

你可能感兴趣的:(right)