标签:style class blog c code http
PS:发现C++里有个很好玩的 函数 string(),头文件必须是<string>,不能是<string.h> ,下面因为memset(),所以我又定义了<string.h>,string()可以直接定义 字符串,但是需要C++强大的输入流,scanf无法使用, 字符串长度 a.lenth(); C++里面函数很棒,想从C 转型到C++了,以后打代码,尽量使用C++
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
const int c = 2001;
using namespace std;
int r[c];
int main()
{
string a,b;
int st=0,len1,len2,i=0,num=0,t;
while(cin>>a>>b)
{
memset(r,0,sizeof(r));
len1=a.length();
len2=b.length();
st=0,i=0,num=0;
while(1)
{
t=a[--len1]-'0'+b[--len2]-'0' + st;
if(len1==-1 || len2==-1)
break;
(t > 9)?(st = 1):(st = 0);
r[num++]=t%10;
}
if(len2 !=-1)
{
for(i=len2;i>=0;--i)
{
t=b[i]-'0'+st;
(t > 9)?(st = 1):(st = 0);
r[num]=t%10;
num++;
}
}
else if(len1!=-1)
{
for(i=len1;i>=0;--i)
{
t=a[i]-'0'+st;
(t > 9)?(st = 1):(st = 0);
r[num]=t%10;
num++;
}
}
if(st!=0)
cout<<st;
for(i=num-1;i>=0;i--)
cout<<r[i];
puts("");
}
return 0;
}
标签:style class blog c code http
原文地址:http://blog.csdn.net/wjw0130/article/details/26865947