#include<iostream>
#include <string>
using namespace std;
/*
int main()
{
int sum[1000];
int temp=0;
string aL;
string bL;
int n1,n2,n,tem;
int k,t=1,u,v;
cin >> k;
for (int w = 0; w < k; w++)
{
cin >> aL >> bL;
n1 = aL.length();
n2 = bL.length();
int sum[1000];
int q;
tem = abs(n1 - n2);
if (n1>=n2)
{
q = 0;
int i = n2 - 1;
//cout << "已运行flag1" << endl;
while (i>=0)
{
if (aL[i + tem]-48 + bL[i]-48 +temp>= 10)
{
//cout << aL[i + tem]-48<< " " << bL[i]-48 << " "<<temp<<" "<<i<<endl;
sum[q++] = (aL[i + tem]-48 + bL[i]-48+temp) % 10;
//cout << sum[q-1] << endl;
temp = (aL[i + tem]-48 + bL[i]-48 + temp) / 10;
}
else
{
//cout << aL[i + tem]-48 << " " << bL[i]-48 << " " << temp <<" "<< i<<endl;
sum[q++] = aL[i + tem]-48 + bL[i]-48+temp;
//cout << sum[q - 1] << endl;
temp = (aL[i + tem]-48 + bL[i]-48 + temp) / 10;
}
u = tem;
i--;
}
if ((u==0)&&(temp !=0))
{
sum[q++] = temp;
//cout << sum[q - 1] << endl;
temp = 0;
}
while (u >0)
{
//cout << aL[u - 1]-48 << " " << temp <<" "<<u<< endl;
sum[q++] = (aL[u-1]-48 + temp) % 10;
//cout << sum[q - 1] << endl;
temp = (aL[u - 1]-48 + temp) / 10;;
u--;
}
if (temp !=0)
{
sum[q++] = temp;
//cout << sum[q - 1] << endl;
temp = 0;
}
}
if (n1<n2)
{
q = 0;
int i= n1 - 1;
//cout << "已运行flag2" << endl;
while(i>=0)
{
if (bL[i + tem]-48 + aL[i]-48+temp >= 10)
{
//cout << bL[i + tem]-48 << " " << aL[i]-48 <<" "<<temp<<" "<< i<<endl;
sum[q++] = (bL[i + tem]-48 + aL[i]-48+temp) % 10;
//cout << sum[q-1] << endl;
temp = 1;
}
else
{
//cout << bL[i + tem]-48 << " " << aL[i]-48 << " " << temp <<" "<<i<< endl;
sum[q++] = bL[i + tem]-48 + aL[i]-48+temp;
//cout << sum[q-1] << endl;
temp = (bL[i + tem]-48 + aL[i]-48 + temp) / 10;
}
v = tem;
i--;
}
if ((v == 0) && (temp != 0))
{
sum[q++] = temp;
temp = 0;
}
while (v>0)
{
//cout << bL[v - 1]-48 << " " << temp <<" "<< v<<endl;
sum[q++] = (bL[v-1]-48 + temp) % 10;
//cout << sum[q-1] << endl;
temp = (bL[v-1]-48 + temp) / 10;
v--;
}
if (temp !=0)
{
sum[q++] = temp;
temp = 0;
}
}
cout << "Case" << " " << w + 1 << ":" << endl;
cout << aL<<" + "<<bL<<" = ";
//cout << " " << "+" << " ";
//cout << bL;
//cout << " " << "=" << " ";
for (int i = q-1; i>=0; i--)
{
//cout << t++ << endl;
cout << sum[i];
}
cout << endl;
if (w < k- 1) cout << endl;
//cout <<"\n"<< endl;
}
return 0;
}*/
杭电1002 A + B Problem II
最新推荐文章于 2023-07-21 09:50:06 发布