HDU:Integer Inquiry
#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的更多相关文章
- hdu 1047 Integer Inquiry
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1047 Integer Inquiry(高精度数)
Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hi ...
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:679 解决:357 题目描述: One of the first users of BIT's new supercomputer was ...
- hdu 1047 Integer Inquiry(大数)
题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...
- HDU 1047 Integer Inquiry 大数相加 string解法
本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...
- HDU 1047 Integer Inquiry( 高精度加法水 )
链接:传送门 思路:高精度水题 /************************************************************************* > File ...
- Poj 1503 Integer Inquiry
1.链接地址: http://poj.org/problem?id=1503 2.题目: Integer Inquiry Time Limit: 1000MS Memory Limit: 1000 ...
- Integer Inquiry【大数的加法举例】
Integer Inquiry Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27730 Accepted: 10764 ...
随机推荐
- windows安装pip 和easy_install
先安装windows版的easy_install 下载 然后下载pip ,python setup.py install 安装好的 pip和easy_install通常在 python目录的 Scr ...
- Private strand flush not complete
当切换日志的时候,所有private strands的内容都会被flush到当前的日志中,然后日志切换才可以完成. strand是在oracle 10g中引入的新术语,和redo的latches相关. ...
- Nginx简介
序言Nginx 是 lgor Sysoev 为俄罗斯访问量第二的 rambler.ru 站点设计开发的.从 2004 年发布至今,凭借开源的力量,已经接近成熟与完善.Nginx 功能丰富,可作为 HT ...
- RMQ求区间最值 nlog(n)
转载于:http://blog.csdn.net/xuzengqiang/article/details/7350465 RMQ算法全称为(Range Minimum/Maximum Query)意思 ...
- wamp多站点配置
1.修改wamp安装目录下:\wamp\bin\apache\Apache2.2.21\conf\extra中的httpd-vhosts.conf文件如下: 2.修改wamp-apache-httpd ...
- C++之路起航——标准模板库(queue)
queue: FIFO队列:先进先出队列. 优先队列:对队列中的元素按优先级的大小输出. 定义: FIFO队列: queue<数据类性>变量名. 优先队列:priority_queue&l ...
- (转)oracle 查看表所占用的空间大小
1.查看表所占空间 SELECT TABLESPACE_NAME,TO_CHAR(SUM(BYTES)/(1024*1024),'999G999D999') CNT_MB FROM ...
- 为archlinux安装mplayer
很简单的一条命令: pacman -S mplayer 安装完之后是字符界面的,所以你还需要一个图形前端: pacman -S gnome-mplayer
- zw版【转发·台湾nvp系列Delphi例程】HALCON InpaintingCt1
zw版[转发·台湾nvp系列Delphi例程]HALCON InpaintingCt1 unit Unit1;interfaceuses Windows, Messages, SysUtils, Va ...
- hibernate笔记01