A+B Problem IV

时间限制:1000 ms  |           内存限制:65535 KB
难度:3
 
描述
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的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. 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 ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [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 ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. E20171015-hm

    quirk   n. 怪癖; 奇事,巧合; 突然的弯曲; propagation  n. 宣传; 传播,传输,蔓延,扩展,波及深度; [生]繁殖法,[地]传导; 培养; immediate  adj. ...

  2. codevs1669 运输装备(背包dp)

    1669 运输装备  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond   题目描述 Description 德国放松对英国的进攻后,把矛头指向了东北——苏联 ...

  3. Codeforces Round #419

    A Karen and Morning 找最近的回文时间 模拟  往后推 判判就行 //By SiriusRen #include <bits/stdc++.h> using namesp ...

  4. Java多线程——线程八锁案例分析

    Java多线程——线程八锁案例分析 摘要:本文主要学习了多线程并发中的一些案例. 部分内容来自以下博客: https://blog.csdn.net/dyt443733328/article/deta ...

  5. 一篇文章告诉你如何使用EF CodeFirst做增删改查

    一.修改数据 其实修改涉及的内容挺多的,是相对于其他操作来说比较繁琐.也是本文的重头戏. 虽然都是基础内容,但是也是值得细细品味的. 1.最简单直接的修改数据就是从数据库里检索出数据修改相应的字段即可 ...

  6. Android各种函数单位

    该博客随时更新.因为每次写函数都会考虑这个单位是什么,所以嫌比较麻烦,在这里总结一下,方便以后使用. paint.setStrokeWidth() 单位是 px . paint.getStrokeWi ...

  7. maven——项目构建和依赖管理工具

    apache maven是一个用于项目构建和依赖管理的工具. 添加archetype https://repo1.maven.org/maven2/archetype-catalog.xml 更改本地 ...

  8. 【PL/SQL】用星号拼出金字塔

    代码中首先声明了几个变量,然后使用嵌套循环去输出空格和星号,其中: 每层空格数=总层数-该层层数 每层星号数=当前层数*2-1 代码如下: declare v_number1 ); --外层循环控制金 ...

  9. 【译】x86程序员手册21-6.3.5为操作系统保留的指令

    6.3.5 Some Instructions are Reserved for Operating System 为操作系统保留的一些指令 Instructions that have the po ...

  10. 3星|《管理十诫》:十年前可口可乐退休CEO的一生管理经验总结

    管理十诫:影响你一生的管理哲学 英文书应该是2008年出版的.国内出版过几个译本. 作者是可口可乐CEO.本书是他从可口可乐CEO退下来后写的管理经验总结.作者总结了11条CEO不应该做的事.这11条 ...