戏雷chnos.blog.chinaunix.net
chnos
全部博文(41)
ACM UVA题(38)
2012年(8)
2011年(1)
2009年(32)
止觞
分类: C/C++
2009-04-16 20:38:22
/* ******************************************************************************* * * Filename: 10035.c * * Author: Ye Xiaofeng , yexfeng # gmail.com * ******************************************************************************* */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { char buffer1[10]; char buffer2[10]; char result_buffer[30]; char *p1_start, *p2_start; char *p2, *p1; int num; int carray_flag; int result; int i; scanf("%s", &buffer1); scanf("%s", &buffer2); while (buffer1[0] != '0' || buffer2[0] != '0') { p1 = buffer1 + strlen(buffer1) - 1; p2 = buffer2 + strlen(buffer2) - 1; num = 0; while (p1 >= buffer1 || p2 >= buffer2) { if (p1 < buffer1) { result_buffer[num] = *p2 - '0'; p2--; } else if (p2 < buffer2) { result_buffer[num] = *p1 - '0'; p1--; } else { result_buffer[num] = *p1 + *p2 - 2 * '0'; p1--; p2--; } num++; } carray_flag = 0; result = 0; for (i = 0; i < num; i++) { if (carray_flag + result_buffer[i] >= 10) { carray_flag = 1; result++; } else { carray_flag = 0; } } /* Output results */ if (result == 0) { printf("No carry operation.\n"); } else if (result == 1) { printf("1 carry operation.\n"); } else { printf("%d carry operations.\n", result); } scanf("%s", &buffer1); scanf("%s", &buffer2); } }
上一篇:ACM UVA (10004)
下一篇:ACM UVA (10183)
登录 注册