#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 105
int a[N];
int main()
{
int i,j,n,n1,flag;
char ch[N];
scanf("%d",&n);
while(n--)
{
memset(a,,sizeof(a)); //数组初始化为零
while(scanf("%s",ch),ch[]!='') //输入零结束
{
n1=strlen(ch);
for(i=n1-,j=;i>=;i--)
{
a[j++]+=ch[i]-'';
a[j]+=a[j-]/; //进位
a[j-]%=; //取余
}
}
flag=;
for(i=N-;i>;i--)
{
if(flag)
printf("%d",a[i]);
else if(a[i])
{
printf("%d",a[i]);
flag=;
}
}
printf("%d\n",a[]); //输入0时应输出0,错了n多次
if(n) //输出块之间有空行
printf("\n");
}
return ;
}

改版 为什么一直WA

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 105
int a[N],b[N];
int main()
{
int i,j,n,n1,flag;
char ch[N];
scanf("%d",&n);
while(n--)
{
memset(a,,sizeof(a)); //数组初始化为零
while(scanf("%s",ch),ch[]!='') //输入零结束
{
n1=strlen(ch);
memset(b,,sizeof(b));
for(i=,j=n1-;j>=;j--,i++)
b[i]=ch[j]-'';
int h=;
int m;
for(i=;i<n1;i++)
{
m=a[i]+b[i]+h;
a[i]=m%;
h=m/;
}
while(h)
{
a[i]=h%;
n1++;
h=h/;
}
}
flag=;
for(i=N-;i>;i--)
{
if(flag)
printf("%d",a[i]);
else if(a[i])
{
printf("%d",a[i]);
flag=;
}
}
printf("%d\n",a[]); //输入0时应输出0,错了n多次
if(n) //输出块之间有空行
printf("\n");
}
return ;
}

C++版本

#include<iostream>
#include<cstring>
using namespace std;
#define N 110
int main()
{
int t;
cin>>t;
while(t--)
{
int sum[N]={0}; char str[N];
while(cin>>str&&str[0]!='0')
{
int num[N]={0};
int len=strlen(str);
for(int i=0;i<len;i++)
num[i]=str[len-1-i]-'0';
for(int i=0;i<N;i++)
{
sum[i]+=num[i];
if(sum[i]>9)
{
sum[i]-=10;
sum[i+1]+=1;
}
//sum[i+1]+=(sum[i]+num[i])/10;
//sum[i]=(sum[i]+num[i])%10;
}
}
int k=N-1;
while(sum[k]==0) k--;
if(k<0)
cout<<0;
else
for(;k>=0;k--)
cout<<sum[k];
cout<<endl;
if(t)
cout<<endl;
} return 0;
}
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int N=;
int main()
{
int a[N],b[N],c,d,ou,kl;
string s1,s2;
getline(cin,s1);
c=s1.length();
ou=;
for (int i=;i<N;i++)//把s1h装到a[100]里
{
a[N--i]=s1[c--i]-'';
if(c--i<)
{
a[N--i]=;
}
}
while(getline(cin,s2)&&s2!="")
{
d=s2.length();
for (int k=;k<N;k++)//把s2装到b[100]里
{
b[N--k]=s2[d--k]-'';
if(d--k<)
{
b[N--k]=;
}
}
for (int l=N-;l>;l--)//做加法
{
a[l]+=b[l];
if(a[l]>=)
{
a[l]-=;
a[l-]++;
}
}
}
for (int g=;g<N;g++)//从不为零的位置开始输出到最后一位
{
ou+=a[g];
if(ou!=)
cout<<a[g];
}
cout<<endl; return ;
}

HDU:Integer Inquiry的更多相关文章

  1. hdu 1047 Integer Inquiry

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...

  2. hdu acm-1047 Integer Inquiry(大数相加)

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. hdu 1047 Integer Inquiry(高精度数)

    Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hi ...

  4. 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:679 解决:357 题目描述: One of the first users of BIT's new supercomputer was ...

  5. hdu 1047 Integer Inquiry(大数)

    题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...

  6. HDU 1047 Integer Inquiry 大数相加 string解法

    本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...

  7. HDU 1047 Integer Inquiry( 高精度加法水 )

    链接:传送门 思路:高精度水题 /************************************************************************* > File ...

  8. Poj 1503 Integer Inquiry

    1.链接地址: http://poj.org/problem?id=1503 2.题目: Integer Inquiry Time Limit: 1000MS   Memory Limit: 1000 ...

  9. Integer Inquiry【大数的加法举例】

    Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27730   Accepted: 10764 ...

随机推荐

  1. python+selenium实现跨浏览器兼容性测试

    python https://www.python.org/ python是一种脚本语言, 易学易用,可以助你快速实现业务逻辑,高效集成系统. ----- http://zh.wikipedia.or ...

  2. runcluvfy.sh运行结果

    $ ./runcluvfy.sh stage -pre crsinst -n rac11g1,rac11g2 -verbose Performing pre-checks for cluster se ...

  3. MVC4相关Razor语法以及Form表单

    Razor的布局(Layout) 默认建的工程都自带的了一个_ViewStart.cshtml文件,文件里面的代码如下: @{ Layout = "~/Views/Shared/_Layou ...

  4. Eclipse 文本显示行号

  5. url组成部分

    协议  eg:http 主机IP地址  eg :端口号8080 项目资源地址  eg:目录名,文件夹名

  6. JAVA中extends 与implements区别

    JAVA中extends 与implements有啥区别?1. 在类的声明中,通过关键字extends来创建一个类的子类.一个类通过关键字implements声明自己使用一个或者多个接口.extend ...

  7. JVM中启用逃逸分析

    -XX:+DoEscapeAnalysis 逃逸分析优化JVM原理我们知道java对象是在堆里分配的,在调用栈中,只保存了对象的指针.当对象不再使用后,需要依靠GC来遍历引用树并回收内存,如果对象数量 ...

  8. Deep Learning 深度学习 学习教程网站集锦

    http://blog.sciencenet.cn/blog-517721-852551.html 学习笔记:深度学习是机器学习的突破 2006-2007年,加拿大多伦多大学教授.机器学习领域的泰斗G ...

  9. PAT乙级 1020. 月饼 (25)(只得到23分)

    1020. 月饼 (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 月饼是中国人在中秋佳节时吃的一种传统食 ...

  10. MyEclipse安装插件的三种方法和使用心得

    本文讲解MyEclipse(MyEclipse10)的三种方法,以TestNG为例 Eclipse update site URL:  http://beust.com/eclipse. 一.通过My ...