【水题+字符串】杭电 hdu 1228 A + B

来源:互联网 发布:linux 命令路径 编辑:程序博客网 时间:2024/06/11 00:38


/* THE PROGRAM IS MADE BY PYY *//*----------------------------------------------------------------------------//    Copyright (c) 2012 panyanyany All rights reserved.    URL   : http://acm.hdu.edu.cn/showproblem.php?pid=1228    Name  : 1228 A + B    Date  : Wednesday, February 08, 2012    Time Stage : half an hour    Result:                                                                                                                                                                                                                                                                                                                                              53285382012-02-08 11:53:44Accepted12280MS152K2470 BC++pyyTest Data :Review :偶尔做一做简单题~~要注意zero zero + zero zero = 的情况//----------------------------------------------------------------------------*/#include <cstdio>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std ;#define MEM(a, v)memset (a, v, sizeof (a))// a for address, v for value#define max(x, y)((x) > (y) ? (x) : (y))#define min(x, y)((x) < (y) ? (x) : (y))#define INF(0x3f3f3f3f)#define MAXN(103)#define MAXE(MAXN*(MAXN-1)/2)#define DEBUG/##/// 字符串转为数字inline int getint (char *sz){int i = -1 ;if (!strcmp (sz, "zero"))i = 0 ;else if (!strcmp (sz, "one"))i = 1 ;else if (!strcmp (sz, "two"))i = 2 ;else if (!strcmp (sz, "three"))i = 3 ;else if (!strcmp (sz, "four"))i = 4 ;else if (!strcmp (sz, "five"))i = 5 ;else if (!strcmp (sz, "six"))i = 6 ;else if (!strcmp (sz, "seven"))i = 7 ;else if (!strcmp (sz, "eight"))i = 8 ;else if (!strcmp (sz, "nine"))i = 9 ;return i ;}void scan_two (int &a, int &b){char sz[100], num[100] ;int t, shift ;// 获得整行gets (sz) ;// get aa = 0 ;shift = 0 ;while (1) {// 跳过多余的空格while (*(sz+shift) == ' ')++shift ;// 提取一个单词sscanf (sz + shift, "%s", num) ;// 计算位移shift += strlen (num) ;if ((t = getint(num)) == -1) // 遇到'+'或'='则跳出break ;a = a * 10 + t ;}b = 0 ;while (1){while (*(sz+shift) == ' ')++shift ;sscanf (sz + shift, "%s", num) ;shift += strlen (num) ;if ((t = getint (num)) == -1)break ;b = b * 10 + t ;}}int main (){int a, b ;while (scan_two(a, b), a | b){printf ("%d\n", a + b) ;}return 0 ;}


原创粉丝点击