HDU 1002 A + B Problem II
来源:互联网 发布:linux如何退出vi 编辑:程序博客网 时间:2024/05/17 12:01
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 161989 Accepted Submission(s): 30809
21 2112233445566778899 998877665544332211
Case 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110
这里要运用高精度来运算,用数组来存储数据,可以先定义字符数组,然后在进行字符与数字之间的转换,,最主要的是要考虑到进位的问题(关键)。下面是我的代码:
#include<iostream>
#include<cstring>
using namespace std;
const int MAXN=1000+10;
char str1[MAXN];
char str2[MAXN];
int str3[MAXN];
int str4[MAXN];
int str5[MAXN];
int main()
{
int T;
cin>>T;
int k=0;
while(T--)
{
int i=0;
static int j=1;
memset(str1, 0, sizeof(str1));
memset(str2, 0, sizeof(str2));
memset(str3, 0, sizeof(str3));
memset(str4, 0, sizeof(str4));
cin>>str1;
cin>>str2;
int len1=strlen(str1);
for( i=0; i<len1; i++)
{
str3[i]=str1[len1-i-1]-'0';
}
int len2=strlen(str2);
for(i=0; i<len2; i++)
{
str4[i]=str2[len2-i-1]-'0';
}
int c=0;
for( i=0; i<MAXN; i++)
{
str5[i]=str3[i]+str4[i]+c;
c=str5[i]/10;
str5[i]%=10;
}
for(i=MAXN-1; i>=0 && str5[i]==0;i--);
cout<<"Case "<<j++<<":"<<endl;
cout<<str1<<" + "<<str2<<" = ";
if(i>=0)
{
for(; i>=0; i--)
{
cout<<str5[i];
}
}
cout<<endl;
if(T-1>=0)
{
cout<<endl;
}
}
return 0;
}
- HDU 1002 A + B Problem II
- HDU 1002A + B Problem II
- HDU 1002 - A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- hdu 1002 A+B Problem II
- HDU 1002 A + B Problem II
- hdu 1002 A + B Problem II
- HDU 1002 A + B Problem II (BigNums)
- hdu 1002 A + B Problem II
- hdu 1002 A + B Problem II
- hdu 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- Hdu---A + B Problem II---1002
- HTC A310E获得root权限详细教程(保证你会)
- CvPoint2D32f
- dom4j的基本操作
- JAVA中的类型转换
- Function
- HDU 1002 A + B Problem II
- C#中DataGridView绑定了DataTable后,通过代码修改DataGridView中的数据,总有一行(被修改过并被用户选中的行集合中索引为0的行)不能被UpDate回数据库的问题和解决办法
- 有些错误就只因没有全局观
- CvPoint3D32f
- MapObject shape数据操作 一
- CvSize
- 今天注册了博客
- linux下创建和删除软、硬链接
- CvSize2D32f