Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Disorganized Example
- ```java
- int i, j, k = 0;
- //Scanner scan = new Scanner(System.in);
- //s = scan.next();
- String s = args[0];
- //System.out.println(s);
- String temp, temp2;
- String tempArray[] = null;
- tempArray = s.split("");
- String suffixes[] = new String[tempArray.length];
- for(i=0; i<tempArray.length; i++) {
- suffixes[i] = "";
- }
- int n = split.length;
- for(i=0; i<n; i++) {
- for(j=i; j<n; j++) {
- suffixes[i] = suffixes[i] + suffixes[j];
- }
- }
- for(i=0; i<suffixes.length-1; i++) {
- int minIndex = i;
- for(j=i; j<suffixes.length; j++) {
- if(suffixes[j].compareTo(suffixes[minIndex]) < 0) {
- minIndex = j;
- }
- }
- temp = suffix[minIndex];
- suffixes[minIndex] = suffixes[i];
- suffixes[i] = temp;
- }
- String result = "";
- for(i=0; i<suffixes.length; i++) {
- result = result + suffixes[i];
- result = result + "\n"
- }
- System.out.print(result);
- ```
- ## Ideal Example
- ```java
- List<String> suffixes = new ArrayList<>();
- for(int i=0; i<args[0].length(); i++) {
- suffixes.add(args[0].substring(i));
- }
- Collections.sort(suffixes);
- for(String s : suffixes) {
- System.out.println(s);
- }
- ```
- ## Ideal outline
- 1. Create a collection of suffixes from the first command line argument
- 1. Initialize the collection
- 2. Iterate over the string to create suffixes, adding them to the collection
- 2. Sort the collection
- 3. Print the collection to the standard output
Add Comment
Please, Sign In to add comment