joj 1189
来源:互联网 发布:华为5a手机壳 淘宝 编辑:程序博客网 时间:2024/05/19 16:38
大数,题目有点误解人。。。明明说VeryLongInteger但运算的却不是数字而是文本行
#include<iostream>
#include<stdio.h>
using namespace std;
char str1[1000005],str2[105];
int main()
{
scanf("%s",str1);
while(scanf("%s",str2),strcmp(str2,"0")!=0)
{
int len1,len2,i=0;
while(str1[i]!='\0')
i++;
len1=i;
i=0;
while(str2[i]!='\0')
i++;
len2=i;
if(len1==len2)
{
int i=len1-1;
int c=0;
while(i>=0)
{
int m=c+str2[i]-'0'+str1[i]-'0';
str2[i]=m%10+'0';
c=m/10;
i--;
}
if(c>0)
{
str1[0]=c+'0';
strcpy(str1+1,str2);
}
else
strcpy(str1,str2);
}
else if(len1<len2)
{
int i=len1-1;
int c=0;
int q=len2-len1;
while(i>=0)
{
int m=c+str2[i+q]-'0'+str1[i]-'0';
str2[i+q]=m%10+'0';
c=m/10;
i--;
}
q--;
while(c&&q>=0)
{
int m=c+str2[q]-'0';
str2[q]=m%10+'0';
c=m/10;
q--;
}
if(c>0)
{
str1[0]=c+'0';
strcpy(str1+1,str2);
}
else
strcpy(str1,str2);
}
else if(len1>len2)
{
int i=len2-1;
int c=0;
int q=len1-len2;
while(i>=0)
{
int m=c+str1[i+q]-'0'+str2[i]-'0';
str1[i+q]=m%10+'0';
c=m/10;
i--;
}
q--;
while(c&&q>=0)
{
int m=c+str1[q]-'0';
str1[q]=m%10+'0';
c=m/10;
q--;
}
if(c>0)
{
strcpy(str2,str1);
str1[0]=c+'0';
strcpy(str1+1,str2);
}
}
}
printf("%s\n",str1);
}
- joj 1189
- JOJ 2257
- joj 2319
- joj 2653
- JOJ 2687
- joj 2693
- joj 2443
- joj 1173
- joj 1003
- joj 1066
- joj 1182
- joj 1195
- joj 1509
- joj 2526
- joj 2426
- joj 1595
- joj 2346
- joj 1169
- 动态生成表
- 7k7k实习学习到的
- 装箱问题 01背包
- poj3080
- 如何在虚拟机中安装MacOS
- joj 1189
- 中国机器人的脊梁
- Asp.net获取客户端CPU,硬盘,MAC序列号的
- 联系各种动态添加表格
- JSP标准标签库之core标签库
- MFC学习总结 (67个技巧)
- sql语句技巧
- 请问机器人定位,国内有那几个牛人?国外又有哪几个牛人
- Python读写,以及修改my.ini文件--针对Python3.0版本