-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLookAndSayGenerator.java
More file actions
53 lines (37 loc) · 1.22 KB
/
LookAndSayGenerator.java
File metadata and controls
53 lines (37 loc) · 1.22 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//2008 - 1
import java.util.*;
public class LookAndSayGenerator{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Scanner inputS = new Scanner(System.in);
int times = input.nextInt();
for(int i = 0; i < times; i++){
String rawIn = inputS.nextLine();
String[] rawS = rawIn.split(" ");
String seed = rawS[0];
int numElements = Integer.parseInt(rawS[1]);
System.out.print(seed + " ");
for(int j = 1; j < numElements; j++){
String newSeed = "";
int number = 1;
for(int x = 0; x < seed.length(); x++){
if(x == seed.length() - 1){
//Last run
newSeed += String.valueOf(number) + seed.charAt(x);//Take out String.valueOf and watch the chaos
break;
}
char letter = seed.charAt(x);
if(letter == seed.charAt(x + 1)){
number++;
} else {
newSeed += String.valueOf(number) + seed.charAt(x);
number = 1;
}
}
System.out.print(newSeed + " ");
seed = newSeed;
}
System.out.println();
}
}
}