nyoj_513_A+B Problem IV_20130131532
A+B Problem IV
- 描述
- acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着能不能写个程序把这个问题给解决了。
- 输入
- 包含多组测试数据 每组数据包含两个正数A,B(可能为小数且位数不大于400)
- 输出
- 每组输出数据占一行,输出A+B的结果,结果需要是最简的形式。
- 样例输入
-
1.9 0.1
0.1 0.9
1.23 2.1
3 4.0 - 样例输出
-
2
1
3.33
7 - 来源
- hdu
#include <stdio.h> #include <string.h>
#define MAX 440
int an1[MAX],an2[MAX],an3[MAX],an4[MAX];
char str1[MAX],str2[MAX],s[2*MAX];
int main()
{
memset(s,0,sizeof(s));
while(gets(s))
{ int i,j,t=0;
int len1,len2,len;
memset(str1,0,sizeof(str1));
memset(str2,0,sizeof(str2));
memset(an1,0,sizeof(an1));
memset(an2,0,sizeof(an2));
memset(an3,0,sizeof(an3));
memset(an4,0,sizeof(an4));
len=strlen(s);
for(i=0,j=0;i<len;i++)
{
if(s[i]==' ')
break;
else
str1[j++]=s[i];
}
for(i+=1,j=0;i<len;i++)
{
str2[j++]=s[i];
}
len1=strlen(str1);
for(i=0;i<len1;i++)
{
if(str1[i]=='.')
{t=i;break;}
}
if(i==len1)
t=i;
for(i+=1,j=1;i<len1;i++)
{
an2[j++]=str1[i]-'0';
}
for(i=t-1,j=0;i>=0;i--)
{
an1[j++]=str1[i]-'0';
}
/*
for(i=0;i<10;i++)
{
printf("%d",an1[i]);
}
for(i=0;i<10;i++)
{
printf("%d",an2[i]);
}
*/
len2=strlen(str2);
t=0;
for(i=0;i<len2;i++)
{
if(str2[i]=='.')
{t=i;break;}
}
if(i==len2)
t=i;
for(i+=1,j=1;i<len2;i++)
{
an4[j++]=str2[i]-'0';
}
for(i=t-1,j=0;i>=0;i--)
{
an3[j++]=str2[i]-'0';
}
for(i=MAX-1;i>=0;i--)
{
an2[i]+=an4[i];
if(an2[i]>=10)
{
an2[i]-=10;
an2[i-1]++;
}
}
if(an2[0]>0)
an1[0]++;
for(i=0;i<MAX;i++)
{
an1[i]+=an3[i];
if(an1[i]>=10)
{
an1[i]-=10;
an1[i+1]++;
}
}
for(i=MAX-1;i>0&&an1[i]==0;i--);
for(;i>=0;i--)
printf("%d",an1[i]);
for(i=MAX-1;i>0&&an2[i]==0;i--);
if(i>0)
{t=i;
printf(".");
for(i=1;i<=t;i++)
printf("%d",an2[i]);
}
printf("\n");
}
return 0;
}
nyoj_513_A+B Problem IV_20130131532的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- Mysql中date,time,datetime,timestamp的区别
区别: timestamp:时间戳.北京时间1970年01月01日08时00分00秒 起至现在的总秒数. datetime:带时分秒的完整时间,例如:1970-01-01 10:00:00 date: ...
- eclipse下整合springboot和mybatis
1.新建maven项目 先新建一个maven项目,勾选上creat a simple project,填写groupid,artifactid 2.建立项目结构 3.添加依赖 <parent&g ...
- Objective-C copy(转)
一.从面向对象到Objective-C概览copy 1.面向对象: In object-oriented programming, object copying is creating a copy ...
- yield from (python生成器)
#生成器中的yield from是干什么用的(一般多用于线程,协程那)def func(): # for i in 'AB': # yield i yield from 'AB' # 就相当于上面的f ...
- hbuilder中的 http://www.w3.org/TR/html4/frameset.dtd
<!-- This is the HTML 4.01 Frameset DTD, which should be used for documents with frames. This DTD ...
- Hadoop Hive概念学习系列之hive里的视图(十二)
不多说,直接上干货! 可以先,从MySQL里的视图概念理解入手 视图是由从数据库的基本表中选取出来的数据组成的逻辑窗口,与基本表不同,它是一个虚表.在数据库中,存放的只是视图的定义,而不存放视图包含的 ...
- Sqoop架构(四)
Sqoop 架构是非常简单的,它主要由三个部分组成:Sqoop client.HDFS/HBase/Hive.Database. 下面是Sqoop 的架构图 (1)用户向 Sqoop 发起一个命令之后 ...
- Redis系列(一)StackExchange.Redis的使用
Redis系列(一)StackExchange.Redis的使用 一.DLL安装 用NuGet搜索StackExchange.Redis,然后下载就可以. ConnectionMultiplexer对 ...
- 行动起来:转换传统桌面应用程序到UWP 并发布到Windows 应用商店!
一个月前微软发布了桌面应用程序转换器(Desktop Application Converter),让我们可以把现有的桌面应用程序(.NET 4.6.1 或 Win32)轻松转换成 通用 Window ...
- cookie范例
GET /locate/api/getLocByIp?key=C6E22B7D480E3312C74EC7EF013E50C5&callback=bowlder.cb._0 HTTP/1.1 ...