zoukankan      html  css  js  c++  java
  • zoj Integer Inquiry

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=292 

    (水题)题目就是多个大数相加没什么可说的注意点还是那几个,发现大整数的题目多做几道,你就会知道都注意什么了。第一次做的时候什么都不知道考虑,贡献了好几次的WA

     1 #include<stdio.h>
    2 #include<string.h>
    3 #include<iostream>
    4 using namespace std;
    5 #define M 1000000
    6 char str[M];
    7 int a[M],b[M];
    8 int main()
    9 {
    10 int t,len,i,j;
    11 int len1,len2;
    12 cin>>t;
    13 while(t--)
    14 {
    15 getchar();
    16 len1=len2=len=0;
    17 memset(a,0,sizeof(a));
    18 memset(b,0,sizeof(b));
    19 while(cin>>str,strcmp(str,"0"))
    20 {
    21 len1=strlen(str);
    22 len2=len;
    23 i=0;
    24 for(j=len1-1;j>=0;j--)
    25 a[i++]=str[j]-'0';
    26 len=len1>len2?len1:len2;
    27 for(i=0;i<=len;i++)
    28 {
    29 b[i]+=a[i];
    30 if(b[i]>9)
    31 {
    32 b[i]-=10;
    33 b[i+1]++;
    34 }
    35 }
    36 memset(a,0,sizeof(a));
    37 }
    38 i=len+1;
    39 int flag=0;
    40 while(!b[i])
    41 {
    42 i--;
    43 if(i==-1)
    44 {
    45 cout<<"0"<<endl;
    46 flag=1;break;
    47 }
    48 }
    49 if(flag)continue;
    50 for(j=i;j>=0;j--)
    51 cout<<b[j];
    52 cout<<endl;
    53 if(t) cout<<endl;
    54
    55 }
    56 return 0;
    57 }


  • 相关阅读:
    汉语-词语:理解
    汉语-词语:头脑
    SELECT INTO
    SELECT
    scp
    samba
    rpmgraph
    rpmdeps
    rpmcache
    rpmbuild
  • 原文地址:https://www.cnblogs.com/fxh19911107/p/2274587.html
Copyright © 2011-2022 走看看