P1601 A+B Problem(高精)
纯代码记录
#include <iostream>using namespace std;int a[505],b[505];
int aD,bD;int res[505];/// @brief 结果会是反着的,方便进一位的处理,直接多一个位然后加在尾部
/// @param a
/// @param aD
/// @param b
/// @param bD
/// @param res
/// @param resD
void myAdd(int a[],int aD,int b[],int bD,int res[],int& resD)
{resD = 0;while(bD>0)res[++resD]=b[bD--];resD = 0;int carry = 0;//进位while(aD>0){res[++resD] += a[aD--] + carry;carry = res[resD]/10;res[resD] %= 10;}if(carry>0)res[++resD] = carry;
}int main()
{//定制本题快读char ch=getchar();aD=bD=0;while(ch<='9' && ch >='0'){a[++aD]=ch-'0';ch=getchar();}while(ch>'9' || ch <'0'){ch=getchar();}while(ch<='9' && ch >='0'){b[++bD]=ch-'0';ch=getchar();}int resD;if(bD<aD)myAdd(a,aD,b,bD,res,resD);elsemyAdd(b,bD,a,aD,res,resD);//答案输出for (int i = resD; i >= 1; i--)printf("%d",res[i]);
}