Submission #66573797
Source Code Expand
import java.lang.*;
import java.util.*;
public class Main{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s= new Scanner(System.in);
int t =s.nextInt();
while(t-->0){
int n =s.nextInt();
String k =s.next();
int indexF = -1;
for(int i = 0; i< n -1; i++){
if (k.charAt(i) > k.charAt(i+1)) {
indexF = i;
break;
}
}
if (indexF == -1) {
System.out.println(k);
continue;
}
int last = indexF;
for(int i =indexF ; i< n; i++){
last = i;
if ( k.charAt(i) > k.charAt(indexF)) {
last = i-1;
break;
}
}
StringBuilder sb = new StringBuilder();
sb.append(k.subSequence(0, indexF));
sb.append(k.subSequence(indexF+1, last+1));
sb.append(k.charAt(indexF));
sb.append(k.subSequence(last+1,k.length() ));
System.out.println(sb.toString());
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - String Rotation |
| User | Reuben9027 |
| Language | Java (OpenJDK 17) |
| Score | 400 |
| Code Size | 1332 Byte |
| Status | AC |
| Exec Time | 302 ms |
| Memory | 57588 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt |
| All | 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 71 ms | 38108 KiB |
| 01_test_01.txt | AC | 289 ms | 57000 KiB |
| 01_test_02.txt | AC | 293 ms | 57588 KiB |
| 01_test_03.txt | AC | 302 ms | 57436 KiB |
| 01_test_04.txt | AC | 291 ms | 57024 KiB |
| 01_test_05.txt | AC | 127 ms | 40268 KiB |
| 01_test_06.txt | AC | 145 ms | 40824 KiB |
| 01_test_07.txt | AC | 137 ms | 40928 KiB |
| 01_test_08.txt | AC | 138 ms | 40920 KiB |
| 01_test_09.txt | AC | 91 ms | 38396 KiB |
| 01_test_10.txt | AC | 110 ms | 39872 KiB |
| 01_test_11.txt | AC | 123 ms | 40496 KiB |
| 01_test_12.txt | AC | 125 ms | 40724 KiB |
| 01_test_13.txt | AC | 125 ms | 40676 KiB |
| 01_test_14.txt | AC | 126 ms | 40452 KiB |
| 01_test_15.txt | AC | 125 ms | 40492 KiB |
| 01_test_16.txt | AC | 123 ms | 41116 KiB |
| 01_test_17.txt | AC | 180 ms | 46620 KiB |