【ACM】nyoj_103_A+BII_201307291022
A+B Problem II
时间限制:3000 ms | 内存限制:65535 KB
难度:3
描述
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
A,B must be positive.
输入
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
输出
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation.
样例输入
2
1 2
112233445566778899 998877665544332211
样例输出
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
#include <stdio.h>
#include <string.h>
#define MAX_LEN 1000
int an1[MAX_LEN+100];
int an2[MAX_LEN+100];
char str1[MAX_LEN+100];
char str2[MAX_LEN+100];
int main()
{
int k,N;
scanf("%d",&N);
for(k=1;k<=N;k++)
{
int i,j,len1,len2;
memset(an1,0,sizeof(an1));
memset(an2,0,sizeof(an2));
scanf("%s%s",str1,str2);
len1=strlen(str1);
for(j=0,i=len1-1;i>=0;i--)
an1[j++]=str1[i]-'0';
len2=strlen(str2);
for(j=0,i=len2-1;i>=0;i--)
an2[j++]=str2[i]-'0';
for(i=0;i<MAX_LEN;i++)
{
an1[i]+=an2[i];
if(an1[i]>=10)
{
an1[i]-=10;
an1[i+1]++;
}
}
printf("Case %d:\n",k);
printf("%s + %s = ",str1,str2);
for(i=MAX_LEN+100;(i>=0)&&(an1[i]==0);i--);
if(i>=0)
for(;i>=0;i--)
printf("%d",an1[i]);
else
printf("0");
printf("\n");
}
return 0;
}
hdu_1002_A+BII_bignum_201307291100
#include <stdio.h>
#include <string.h>
#define MAX_LEN 1000
int an1[MAX_LEN+100];
int an2[MAX_LEN+100];
char str1[MAX_LEN+100];
char str2[MAX_LEN+100];
int main()
{
int k,N,t=0;
scanf("%d",&N);
for(k=1;k<=N;k++)
{
int i,j,len1,len2;
memset(an1,0,sizeof(an1));
memset(an2,0,sizeof(an2));
scanf("%s%s",str1,str2);
len1=strlen(str1);
for(j=0,i=len1-1;i>=0;i--)
an1[j++]=str1[i]-'0';
len2=strlen(str2);
for(j=0,i=len2-1;i>=0;i--)
an2[j++]=str2[i]-'0';
for(i=0;i<MAX_LEN;i++)
{
an1[i]+=an2[i];
if(an1[i]>=10)
{
an1[i]-=10;
an1[i+1]++;
}
}
printf(t++?"\nCase %d:\n":"Case %d:\n",k);
printf("%s + %s = ",str1,str2);
for(i=MAX_LEN+100;(i>0)&&(an1[i]==0);i--);
for(;i>=0;i--)
printf("%d",an1[i]);
printf("\n");
}
return 0;
}
较之上个程序有所修改,输出部分有所简化
【ACM】nyoj_103_A+BII_201307291022的更多相关文章
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- 【ACM】HDU1008 Elevator 新手题前后不同的代码版本
[前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...
- 【ACM】魔方十一题
0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...
- 【ACM】那些年,我们挖(WA)过的最短路
不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...
- 【ACM】不要62 (数位DP)
题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...
- 【Acm】八皇后问题
八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...
- 【ACM】hud1166 敌兵布阵(线段树)
经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...
- 【acm】杀人游戏(hdu2211)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others) M ...
- 【ACM】How many prime numbers
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=2 #inclu ...
随机推荐
- Android EditText技巧总结
一.默认不获取焦点: 在布局文件的父控件中,设置如下属性: android:focusable="true" android:focusableInTouchMode=" ...
- Android中关闭DatePicker、TimePicker、NumberPicker的可编辑模式
DatePicker.TimePicker.NumberPicker这三个控件在使用的过程中,用户点击数字会弹出键盘,有时候会造成布局被挤压不好看,也有其他的需求. 我看了网上很多文章的解决办法都无效 ...
- Spring:延迟初始化
ApplicationContext实现的默认行为就是在启动时将所有singleton bean提前进行实例化.提前实例化意味着作为初始化过程的一部分,ApplicationContext实例会创建并 ...
- mac os lscpu 【转】
CPU Information on Linux and OS X This is small blog post detailing how to obtain information on you ...
- Too-Java:Intellij Idea
ylbtech-Too-Java:Intellij Idea IDEA 全称 IntelliJ IDEA,是java编程语言开发的集成环境.IntelliJ在业界被公认为最好的java开发工具之一,尤 ...
- hdu 3037Saving Beans(卢卡斯定理)
Saving Beans Saving Beans Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- 浅谈JavaScript中的cookie
什么是cookie?简单来说,cookie就是网站服务器存放在我们计算机上的一小段(一般大小不超过4KB)用来识别和记录用户的个人信息的文本.HTTP协议是一种没有“状态”的传输协议,也就是说,服务器 ...
- bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6
自己写了个Django系统,用到了Django-bootstrap3结果在浏览器控制台发现报错:bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaS ...
- 自学Python八 爬虫大坑之网页乱码
Bug有时候破坏的你的兴致,阻挠了保持到现在的渴望.可是,自己又非常明白,它是一种激励,是注定要被你踩在脚下的垫脚石! python2.7中最头疼的可能莫过于编码问题了,尤其还是在window环境下, ...
- CSS清除浮动_清除float浮——详解overflow:hidden 与clear:both属性
最近刚好碰到这个问题,看完这个就明白了.写的很好,所以转载了! CSS清除浮动_清除float浮动 CSS清除浮动方法集合 一.浮动产生原因 - TOP 一般浮动是什么情况呢?一般是一个盒子里 ...