zoukankan      html  css  js  c++  java
  • Integer Inquiry

    题目连接:http://bak2.vjudge.net/contest/135820#problem/C

    题目大意: 大数相加用字符串,输入0时输入结束,如果只输入一个0,那么要输出0。。要特别注意特殊情况。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    char s[105],s1[105];
    int a1[105];
    void add(char s1[],int a1[])
    {
        int a2[105];
        for(int j=0,i=strlen(s1)-1;i>=0;i--)
        a2[j++]=s1[i]-'0';
        for(int i=0;i<strlen(s1);i++)
        {
            a1[i]=a1[i]+a2[i];
            if(a1[i]>=10)
            {
                a1[i]=a1[i]%10;
                a1[i+1]++;
            }
        }
    
    }
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--)
        {
             int coun=0;
            memset(a1,0,sizeof(a1));
            while(scanf("%s",s)!=EOF)//此处不需要取址符,s就代表了地址,并且不能输入空格,但gets()可以
            {
                coun++;
                if(s[0]=='0') break;
                add(s,a1);
    
            }
            if(coun==1) printf("0");
            int g;
            for( g=104;g>=0;g--)
                if(a1[g]!=0) break;
            for(int j=g;j>=0;j--)
            printf("%d",a1[j]);
            printf("
    ");
           if(n!=0) printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    [VC++]轻松搞VC之定时器(Timer)
    [VC++]VC中如何获得当前系统时间
    [VC++]如何利用this获得窗口句柄
    SMART原则
    SQL配置
    术语百科
    关于SQL锁问题
    第六代OA办公理念(摘录)
    心动机型
    SQL2008R2的索引重建
  • 原文地址:https://www.cnblogs.com/Twsc/p/5950849.html
Copyright © 2011-2022 走看看