8053535 | CodeChef

//https://www.codechef.com/LRNDSA01/problems/FLOW007
in C++
#include
#include
using namespace std;

int main() {
int t;
string a;
cin>>t;
while(t–)
{
string b;
cin>>a;
for(int i=a.length()-1;i>=0;i–)
b[a.length()-i-1]=a[i];
cout<<stoi(b);
cout<<endl;
b.clear();
}

return 0;

}

Why is my output coming as:
54321
30213
32123
323

is b.clear() not working? why is the last digit of previous test case remin in the new test case?

However,
#include
#include
using namespace std;

int main() {
int t;
string a;
cin>>t;
while(t–)
{
string b;
b=a;
cin>>a;
for(int i=a.length()-1;i>=0;i–)
b[a.length()-i-1]=a[i];
cout<<stoi(b);
cout<<endl;
}

return 0;

}
This is working