hdu-A+B问题,大数加法
格式问题很头疼啊
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int N;
int count=1;
scanf("%d",&N);
getchar();
char str1[1001],str2[1001];定义两个数组
while(N--)
{
int i=0;
int lenmax;
int a[1001]={0},b[1001]={0},c[1001]={0};
scanf("%s",str1);
int len1=strlen(str1);
for(i=0;i<len1;i++)
{
a[i]=str1[len1-1-i]-'0';
}
scanf("%s",str2);
int len2=strlen(str2);
for( i=0;i<len2;i++)
{
b[i]=str2[len2-1-i]-'0';
}
if(len1>=len2)
lenmax=len1;
else
lenmax=len2;
int k=0;
for( i=0;i<lenmax;i++)
{
c[i]=(a[i]+b[i]+k)%10;
k=(a[i]+b[i]+k)/10;
}
if(k!=0)
{
c[lenmax]=1;
}
int n=1;
printf("Case %d:\n",count);
count++;
printf("%s + %s = ",str1,str2);
if(c[lenmax]==1)
{
printf("1");
}
for( i=lenmax-1;i>=0;i--)
{
printf("%d",c[i]);
}
printf("\n");
if(N>=1)
printf("\n");
}
return 0;
}
hdu-A+B问题,大数加法的更多相关文章
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
- HDU——1715大菲波数(大数加法)
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- Hat's Fibonacci(大数加法+直接暴力)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...
- A + B Problem II(大数加法)
http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Other ...
- ZZNU 2125:A + B 普拉斯(傻逼题+大数加法)
2125: A + B 普拉斯 时间限制: 1 Sec 内存限制: 128 MB 提交: 94 解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 "别人总说 ...
- 51nod 1005 大数加法
#include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...
- c#大数加法
在C#中,我们经常需要表示整数.但是,c#的基本数据类型中,最大的long也只能表示-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807之间的数 ...
- 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)
题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...
- Leetcode 67 Add Binary 大数加法+字符串处理
题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...
随机推荐
- 【17】以独立语句将newed对象置入智能指针
1.为什么? 考虑下面的情况:方法声明为void processWidget(shared_ptr<Widget> pw,int priority). 调用方法 processWidget ...
- jQuery 编辑div内容
div显示如下 <div id="showResult"></div> div中添加的html,进行拼接 $("#showResult" ...
- Android UI开发第三十三篇——Navigation Drawer For Android API 7
Creating a Navigation Drawer中使用的Navigation Drawer的android:minSdkVersion="14",现在Android API ...
- iOS设计模式之生成器
iOS设计模式之生成器 1.生成器模式的定义 (1): 将一个复杂的对象的构件与它的表示分离,使得相同的构建过程能够创建不同的表示 (2): 生成器模式除了客户之外还包括一个Director(指导者) ...
- SensorThread线程
SensorThread && createEventQueue http://www.csdn.com/html/itweb/20131101/200375.htm_123 htt ...
- Block块
block的标志:^ 特点: 1.可以保存代码 2.有返回值 3.有形参 4.调用方式和c语言一样 5.可以访问外部变量,但不能修改变量的值:如果使用__block关键字修饰的变量才可以. 1)创建 ...
- Java并发(6)带返回结果的任务执行
携带结果的任务 JDK5提供了有可返回值的任务的执行.java.util.concurrent中Callable与Futrue用以实现带返回值的任务执行. 使用Callable与Futrue与使用Ru ...
- CentOS6.4安装ati显卡驱动
台式机安装CentOS 6.4 x86_64位 集成显卡ati4290 CentOS的release notes上: The proprietary drivers for older AMD ( ...
- /Users/XX/Library/Developer/Xcode/DerivedData/XX.app/xxsdk.bundle Directory not empty
今天在升级xcode后真机调试偶然发现这个问题,查了一些资料发现还是不能完全解决 解决方法:参考的(http://blog.csdn.net/alincexiaohao/article/details ...
- javascript 函数学习
1.自以为好的部分,更多访问: http://www.runoob.com/js/js-tutorial.html 2.this 3.new 4.闭包 5.自执行