#include
#include
#include<string.h>
using namespace std;
int main()
{
int i,a[100],n,j,no;
string s[100],sum;
cin>>n;
for(i=0; i<n; i++)
{
cin>>a[i];
stringstream st;
st<<a[i];
s[i]=st.str();
}
for(i=0 ;i<n-1; i++)
{
j=i+1;
while(j<n)
{
if((s[j]+s[i])>(s[i]+s[j]) )
{
swap(s[j],s[i]);
}
j++;
}
}
for(i=0; i<n; i++)
{
sum=sum+s[i];
}
cout<<sum<<endl;
istringstream(sum)>>no;
cout<<no;
return 0;
}
the sum variable which is a string is showing the right output but when I am converting that string into integer then the output changes. what problem is there in the code?