시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 69 | 46 | 45 | 72.581% |
Given an integer A, only other integers that are permutations of A are useful. All other numbers are useless. Find the next largest integer B, where the digits in B is a permutation of the digits of A. For example, suppose A=2413, then the next largest permutation is 2431. If A is already the largest permutation, output “USELESS”.
The first line in the data file is an integer that represents the number of data sets to follow. Each line is a single integer A (A <= 2,000,000).
Print B, the next largest permutation. If it doesn’t exist print “USELESS”.
4 237531 1234 4321 3444
251337 1243 USELESS 4344