Advertisement
Guest User

Untitled

a guest
Sep 8th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <stack>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <string>
  10. #include <algorithm>
  11. #include <iostream>
  12. using namespace std;
  13.  
  14. int p;
  15. char s[100];
  16.  
  17. int main() {
  18.     //freopen("input.txt", "r", stdin);
  19.     //freopen("output.txt", "w", stdout);
  20.  
  21.     scanf("%d", &p);
  22.     for (int tst = 1; tst <= p; tst++) {
  23.         scanf("%*d %s", s);
  24.         int l = strlen(s), a, b;
  25.         for (a = l - 2; a >= 0 && s[a] >= s[a + 1]; a--);
  26.         if (a == -1) {
  27.             printf("%d BIGGEST\n", tst);
  28.             continue;
  29.         }
  30.         for (b = l - 1; b > a && s[b] <= s[a]; b--);
  31.         swap(s[a], s[b]);
  32.         sort(s + a + 1, s + l);
  33.         printf("%d %s\n", tst, s);
  34.     }
  35.    
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement