Chinaunix首页 | 论坛 | 博客
  • 博客访问: 436569
  • 博文数量: 103
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 971
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-11 17:22
文章分类
文章存档

2008年(77)

2007年(26)

我的朋友

分类: C/C++

2008-03-10 22:36:57


#include <stdio.h>
#include <string.h>

int res[103], a[103];

void jiafa(int a[103], int res[103], int len)
{
        int j = 102, k = len-1;

        for(k; k >= 0; k--, j--){
                res[j] += a[k];
                if(res[j] >= 10){
                        res[j-1]++;
                        res[j] %= 10;
                }
        }

        if(res[j] >= 10){
                while(j >= 0){
                        if(res[j] >= 10){
                                res[j-1]++;
                                res[j] %= 10;
                        }
                        j--;
                }
        }
}

int main(int argc, char **argv)
{
        FILE *fp = NULL;
        char str[103];
        int len, k, temp = 0;

        while(1){
                if((fgets(str, 103, stdin)) && (str[0] == '0') \
                        && (str[1] == '\n')){
                        break;
                }

                len = strlen(str);
                for(k = 0; k < len-1; k++){
                        a[k] = str[k] - 48;
                }

                jiafa(a, res, len-1);
        }

        for(k = 0; k < 103; k++){
                if(res[k]){
                        temp = k;
                        break;
                }
        }

        for(temp; temp < 103; temp++){
                printf("%d", res[temp]);
        }
        printf("\n");

        return 0;
}

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

上一篇:Prob 1003 Hangover

下一篇:volatile 和 sig_atomic_t

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