HOJ 1401Gigantic Sums

HOJ 1401Gigantic Sums
把#include <stdio.h>改成#include<iostream>会超内存
题目意思:求两个数的和,按位相加,边加边输出,找一个变量存9的个数

下面是代码
 1 #include  < stdio.h >
 2
 3 int  main()
 4 {
 5    int n,num,a,b,temp,sum = 0,start = 0;
 6    int i;
 7
 8    while(scanf("%d",&n)==1)
 9    {
10        num = 0;
11        start = 0;
12        while(n--)
13        {
14            scanf("%d%d",&a,&b);
15            temp = a+b;
16            if(temp!=9)
17            {
18                if(!start)
19                {
20                    if(temp>=10)
21                    {
22                        printf("%d",temp/10);
23                        sum = temp-10;
24                    }

25                    else sum = temp;
26                    start = 1;
27                }

28                else
29                {
30                    int flag = 0;
31                    if(temp>=10)
32                    {
33                        printf("%d",sum+1);
34                        flag = 1;
35                    }

36                    else printf("%d",sum);
37                    for(i = 0; i < num; i++)
38                    {
39                        if(flag) printf("0");
40                        else printf("9");
41                    }

42                    num = 0;
43                    sum = temp%10;
44                }

45            }

46            if(temp==9) num++;
47        }

48            printf("%d",sum);
49            if(num)
50            {
51                for(i = 0; i < num; i++) printf("9");
52            }

53            printf("\n");
54    }

55    return 0;
56}

57

你可能感兴趣的:(HOJ 1401Gigantic Sums)