Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int p;
- char s[100];
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- scanf("%d", &p);
- for (int tst = 1; tst <= p; tst++) {
- scanf("%*d %s", s);
- int l = strlen(s), a, b;
- for (a = l - 2; a >= 0 && s[a] >= s[a + 1]; a--);
- if (a == -1) {
- printf("%d BIGGEST\n", tst);
- continue;
- }
- for (b = l - 1; b > a && s[b] <= s[a]; b--);
- swap(s[a], s[b]);
- sort(s + a + 1, s + l);
- printf("%d %s\n", tst, s);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement