I’m getting the correct output ,but an extra “-1” in the following question in SPOJ: http://www.spoj.com/problems/JNEXT/
Here’s my code:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int t;
char ss[10000];
string s;
cin>>t;
++t;
while(t--)
{
getline(cin,s);
s.erase(remove(s.begin(), s.end(),' '), s.end());
if(next_permutation(s.begin(),s.end()))
{cout<<s<<"\n";}
else
{cout<<"-1\n";}
}
return 0;
}
OUTPUT:
2
-1 // unwanted
3 1
-1
1 4 3
314
Pls help