Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. public class SpellCaster {
  4. public static void main(String[] args) {
  5. Scanner in= new Scanner(System.in);
  6. String line = in.nextLine();
  7. String[] words = line.split("\\s");
  8. String removed="";
  9. int [] lengths=new int[words.length];
  10. String lastSymbolsWord="";
  11. boolean allZero=false;
  12. boolean[] isZero= new boolean [words.length];
  13. String alphabet="abcdefghijklmnopqrstuvwxyz";
  14. while(!allZero){
  15. for(int i=0;i<words.length;i++){
  16. if(words[i].length()==0){
  17. isZero[i]=true;
  18. allZero=areAllZero(isZero);
  19. continue;
  20. }
  21. lastSymbolsWord+=lastSymbol(words[i]);
  22. lengths[i]=(words[i].length());
  23. words[i]=removeLastChar(words[i]);
  24. }
  25. }
  26. char[] word=lastSymbolsWord.toCharArray();
  27.  
  28. for(int i=0;i<word.length;i++){
  29. word=shift(word,indexof(word[i]),i);
  30. }
  31. for(int i=0;i<word.length;i++){
  32. System.out.print(word[i]);
  33. }
  34. System.out.println();
  35. System.out.println(lastSymbolsWord);
  36. }
  37. static String lastSymbol(String word) {
  38. return word.substring(word.length() - 1);
  39. }
  40. private static String removeLastChar(String str) {
  41. StringBuilder bulid = new StringBuilder(str);
  42. bulid.deleteCharAt(str.length()-1);
  43.  
  44. return String.valueOf(bulid);
  45. }
  46. private static boolean areAllZero(boolean[] isZeroo){
  47. for(boolean b : isZeroo) if(!b) return false;
  48. return true;
  49. }
  50. static int indexof(char ch){
  51. int index="abcdefghijklmnopqrstuvwxyz".indexOf(ch);
  52. int index1="ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(ch);
  53. if(index<index1){
  54. return index1+1;
  55. }else{
  56. return index+1;
  57. }
  58. }
  59.  
  60. static char[] shift(char[] array, int indexAlpha, int position) {
  61. int length=array.length;
  62. char temp;
  63. int j=position;
  64. char positionChar=array[position];
  65. boolean isFull=false;
  66. for(int i=position;i<indexAlpha+position;i++){
  67. if(j<length-1){
  68. temp=array[j];
  69. array[j]=array[j+1];
  70. array[j+1]=temp;
  71. j++;
  72. }else if(j==length){
  73. temp=array[j];
  74. array[j]=array[0];
  75. array[0]=temp;
  76. j++;
  77. }
  78. }
  79. return array;
  80. }
  81.  
  82. }
  83. /*String str = "M1y java8 Progr5am";
  84. StringBuilder bulid = new StringBuilder(str);
  85. bulid.deleteCharAt(1); // Shift the positions front.
  86. bulid.deleteCharAt(8-1);
  87. bulid.deleteCharAt(15-2);
  88. System.out.println("Builder : "+bulid);
  89. }
  90. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement