Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int t;
  5. long long n, a[100000001];
  6.  
  7. main() {
  8. scanf("%d", &t);
  9. while(t--) {
  10. string res, cur;
  11. scanf("%lld", &n);
  12.  
  13. for(int i = 1 ; i <= n ; ++i) {
  14. scanf("%lld", &a[i]);
  15. char c = a[i] + '0';
  16. cur.append(1, c);
  17. }
  18.  
  19. next_permutation(a + 1, a + n + 1);
  20.  
  21. for(int i = 1 ; i <= n ; ++i) {
  22. char c = a[i] + '0';
  23. res.append(1, c);
  24. }
  25.  
  26. if(cur == res) cout << "-1\n";
  27. else cout << res << endl;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement