joj 1171
2011-11-06 18:44
148 查看
水题,做1089太郁闷了所以刷了到水题,代码很笨,基本没有参考价值,只为看一眼快把我折磨死的气球。。。。。。。。。。。
#include<iostream>
#include<stdio.h>
using namespace std;
char str1[1005],str2[1005];
int main()
{
while(scanf("%s%s",str1,str2)!=EOF)
{
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)
printf("%d%s\n",c,str2);
else
printf("%s\n",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)
printf("%d%s\n",c,str2);
else
printf("%s\n",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)
printf("%d%s\n",c,str1);
else
printf("%s\n",str1);
}
}
}
#include<iostream>
#include<stdio.h>
using namespace std;
char str1[1005],str2[1005];
int main()
{
while(scanf("%s%s",str1,str2)!=EOF)
{
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)
printf("%d%s\n",c,str2);
else
printf("%s\n",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)
printf("%d%s\n",c,str2);
else
printf("%s\n",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)
printf("%d%s\n",c,str1);
else
printf("%s\n",str1);
}
}
}
相关文章推荐
- joj 1171
- JOJ 1058 T9
- JOJ 1109 I-KeyBoar 动态规划
- joj 登不上了……,题写完rt,
- JOJ 2431: Shift and Increment
- joj1008(注意库函数的应用)
- joj2687
- joj 1595 Combinations
- hdu1171_多重背包转化为01背包
- joj 2431: Shift and Increment (模板队列与数组模拟队列的对比练习)
- joj 1131: Intersection (判断直线与矩形是否有交点)
- JOJ2519 Find the longest section(位运算 +(前缀和?))
- JOJ 2724 hua rong dao (最小割 拆点)[无代码]
- joj1082
- joj 1805
- JOJ 2580 Welcome to JL2009
- joj 1317
- joj 2717
- JOJ2573:Product of two primes
- joj1277