首页 > 其他 > 详细

HDU 1228 字符串到数字的转化

时间:2015-01-01 00:05:39      阅读:324      评论:0      收藏:0      [点我收藏+]

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

 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 }

 

HDU 1228 字符串到数字的转化

原文:http://www.cnblogs.com/CSU3901130321/p/4196822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!