Chinaunix首页 | 论坛 | 博客
  • 博客访问: 71874
  • 博文数量: 41
  • 博客积分: 1475
  • 博客等级: 上尉
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-27 22:49
文章分类
文章存档

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);
    }
}

阅读(244) | 评论(0) | 转发(0) |
0

上一篇:ACM UVA (10004)

下一篇:ACM UVA (10183)

给主人留下些什么吧!~~