/*1201. 01000001
大意:简单题 ,纯粹加法操作
*/
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
string add(string a, string b){
while(a.length() < b.length()) a = '0' + a;
while(b.length() < a.length()) b = '0' + b;
int length = a.length();
int z = 0;
for(int i=length-1; i>=0; i--){
int valueA = a[i] - '0';
int valueB = b[i] - '0';
valueA += z + valueB;
z = 0;
if(valueA > 1){
z = 1;
valueA = valueA - 2;
}
a[i] = valueA + '0';
if(i==0 && z == 1)
{
a = '1' + a;
}
}
return a;
}
string clear(string &s){
if(s=="")
s='0';
while(s.length() >0 && s[0] == '0')
s.erase(0,1);
if(s=="")
s = '0';
return s;
}
int main()
{
int testNum;
cin >> testNum;
for(int i=1; i<= testNum; i++){
string a, b;
cin >> a >> b;
string result = add(a,b);
result = clear(result);
cout << i << " " <<result << endl;
}
system("pause");
return 0;
}
1201. 01000001(纯粹加法操作 )
最新推荐文章于 2021-05-23 19:40:05 发布