HDU 1228 字符串到数字的转化

一道水题,练练字符串的输入输出

 1 #include <cstdio>

 2 #include <cstring>

 3 

 4 using namespace std;

 5 char s1[15] , s2[15];

 6 

 7 int get_num(char *s)

 8 {

 9     if(s[0] == 'z') return 0;

10     else if(s[0] == 'o') return 1;

11     else if(s[0] == 't' && s[1] == 'w') return 2;

12     else if(s[0] == 't' && s[1] == 'h') return 3;

13     else if(s[0] == 'f' && s[1] == 'o') return 4;

14     else if(s[0] == 'f' && s[1] == 'i') return 5;

15     else if(s[0] == 's' && s[1] == 'i') return 6;

16     else if(s[0] == 's' && s[1] == 'e') return 7;

17     else if(s[0] == 'e') return 8;

18     else if(s[0] == 'n') return 9;

19 }

20 

21 int main()

22 {

23   //  freopen("a.in" , "r" , stdin);

24     while(1)

25     {

26         int n1 = 0;

27         while(scanf("%s" , s1)){

28             if(s1[0] == '+') break;

29             n1 = n1*10+get_num(s1);

30         }

31         int n2 = 0;

32         while(scanf("%s" , s2)){

33             if(s2[0] == '=') break;

34             n2 = n2*10+get_num(s2);

35         }

36         if(n1 == n2 && n1 == 0)

37             break;

38         printf("%d\n" , n1+n2);

39     }

40     return 0;

41 }

 

你可能感兴趣的:(字符串)