可以請大神告訴我為什麼以下程式會無窮迴圈嗎?
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--){
int p = 0, last = 0, count = 0;
bool flag = true;
string a, b, c;
cin >> p;
while (1){
a = to_string(p);
for (int i = 0; i < a.size(); i++){
b[i] = a[a.size() - i - 1];
}
for (int i = 0; i < b.size(); i++){
last += (int(b[i] - '0') * int(pow(10, b.size() - i - 1)));
}
p += last;
a = to_string(p);
for (int l = 0; l < a.size(); l++){
if (a[l] != a[a.size() - l - 1]){
flag = false;
break;
}
}
if (flag == true){
cout << count+1 << " " << p << "\n";
break;
}
else {
flag = true;
count++;
}
}
}
return 0;
}