/******************************************************* * Copyright (C) 2015 Haotian Wu * * This file is the solution to the question: * https://www.hackerrank.com/challenges/bigger-is-greater * * Redistribution and use in source and binary forms are permitted. *******************************************************/ #include #include #include #include #include #include using namespace std; int main() { int tt; scanf("%d",&tt); char str[101]; while (tt--) { scanf("%s",str); int L=strlen(str), flag=0; for (int i=L-2;i>=0;i--) //Find the rightmost character with str[i]str[i]) { minc=str[j]; minidx = j; } swap(str[i],str[minidx]); //Put the smallest greater character in str[i] sort(str+(i+1), str+L); //Sort the characters on the right printf("%s\n",str); break; } } if (flag==0) printf("no answer\n"); } return 0; }