1074. 宇宙无敌加法器 PAT
`````` #include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
int remain(int num);
int getlength(int num);

int read(int n1)//123   12  1
{
return n1 % 10;
}

int remain(int n2)
{
return n2 / 10;
}

int getlength(int num)
{
int length = 1;
while (remain(num) != 0)
{
length++;
}
cout << length;
return length;

}

int main()
{
int N; //N 位的进制表
int p1, p2;
cin >> N >> p1 >> p2;//30527

int tempd;
int temp1, temp2;

int z = 0;
int jw = 0;
vector <int> output;

int lengthN = getlength(N);////运算次数
//  lengthp1 = getlength(p1);
//  lengthp2 = getlength(p2);
//  cout << lengthN;

for (int i = 0; i < lengthN; i++)
{
tempd = read(N);//当前进制  7
if(tempd == 0)
{
tempd = 10;
}
N = remain(N);

p1 = remain(p1);//0620
p2 = remain(p2);//41

z = (temp1 + temp2 + jw) % tempd;
jw = (temp1 + temp2 + jw) / tempd;
output.push_back(z);

}
if (jw != 0)
{
output.push_back(1);
}

for (int x = output.size() - 1; x >= 0; x--)
{
cout << output[x];
}
}
``````

1074 宇宙无敌加法器（20 分）

30527
06203
415

7201

1个回答

int getlength(int num)
{
int length = 1;
while (remain(num) != 0)
{
length++;
}
cout << length;
return length;

}死循环 停不下来

yuAriellexi 谢谢，疏忽了

xingjianfengaa 或许这样while ((num=remain(num)) != 0)