forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeparateTheNumbers.java
More file actions
30 lines (27 loc) · 925 Bytes
/
SeparateTheNumbers.java
File metadata and controls
30 lines (27 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
/*
* @author -- rajatgoyal715
*/
public class SeparateTheNumbers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
label:
for(int a0 = 0; a0 < q; a0++){
String s = in.next();
for(int i=1;i<s.length();i++){
BigInteger initial = new BigInteger(s.substring(0,i));
int pos = i;
while(s.indexOf(initial.add(new BigInteger("1")).toString(),pos-1)==pos){
pos+=initial.add(new BigInteger("1")).toString().length();
initial = initial.add(new BigInteger("1"));
}
if(pos==s.length()){
System.out.println("YES "+s.substring(0,i));
continue label;
}
}
System.out.println("NO");
}
}
}