daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Disorganized Example
  2.  
  3. ```java
  4. int i, j, k = 0;
  5.  
  6. //Scanner scan = new Scanner(System.in);
  7. //s = scan.next();
  8. String s = args[0];
  9. //System.out.println(s);
  10. String temp, temp2;
  11.  
  12. String tempArray[] = null;
  13. tempArray = s.split("");
  14. String suffixes[] = new String[tempArray.length];
  15. for(i=0; i<tempArray.length; i++) {
  16.     suffixes[i] = "";
  17. }
  18.  
  19. int n = split.length;
  20. for(i=0; i<n; i++) {
  21.   for(j=i; j<n; j++) {
  22.     suffixes[i] = suffixes[i] + suffixes[j];
  23.   }
  24. }
  25.  
  26. for(i=0; i<suffixes.length-1; i++) {
  27.   int minIndex = i;
  28.   for(j=i; j<suffixes.length; j++) {
  29.     if(suffixes[j].compareTo(suffixes[minIndex]) < 0) {
  30.       minIndex = j;
  31.     }
  32.   }
  33.   temp = suffix[minIndex];
  34.   suffixes[minIndex] = suffixes[i];
  35.   suffixes[i] = temp;
  36. }
  37.  
  38. String result = "";
  39. for(i=0; i<suffixes.length; i++) {
  40.   result = result + suffixes[i];
  41.   result = result + "\n"
  42. }
  43. System.out.print(result);
  44. ```
  45.  
  46.  
  47. ## Ideal Example
  48.  
  49. ```java
  50. List<String> suffixes = new ArrayList<>();
  51. for(int i=0; i<args[0].length(); i++) {
  52.   suffixes.add(args[0].substring(i));
  53. }
  54.    
  55. Collections.sort(suffixes);
  56.    
  57. for(String s : suffixes) {
  58.   System.out.println(s);
  59. }
  60. ```
  61.  
  62. ## Ideal outline
  63.  
  64. 1. Create a collection of suffixes from the first command line argument
  65.     1. Initialize the collection
  66.     2. Iterate over the string to create suffixes, adding them to the collection
  67. 2. Sort the collection
  68. 3. Print the collection to the standard output
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top