Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- public class SpellCaster {
- public static void main(String[] args) {
- Scanner in= new Scanner(System.in);
- String line = in.nextLine();
- String[] words = line.split("\\s");
- String removed="";
- int [] lengths=new int[words.length];
- String lastSymbolsWord="";
- boolean allZero=false;
- boolean[] isZero= new boolean [words.length];
- String alphabet="abcdefghijklmnopqrstuvwxyz";
- while(!allZero){
- for(int i=0;i<words.length;i++){
- if(words[i].length()==0){
- isZero[i]=true;
- allZero=areAllZero(isZero);
- continue;
- }
- lastSymbolsWord+=lastSymbol(words[i]);
- lengths[i]=(words[i].length());
- words[i]=removeLastChar(words[i]);
- }
- }
- char[] word=lastSymbolsWord.toCharArray();
- for(int i=0;i<word.length;i++){
- word=shift(word,indexof(word[i]),i);
- }
- for(int i=0;i<word.length;i++){
- System.out.print(word[i]);
- }
- System.out.println();
- System.out.println(lastSymbolsWord);
- }
- static String lastSymbol(String word) {
- return word.substring(word.length() - 1);
- }
- private static String removeLastChar(String str) {
- StringBuilder bulid = new StringBuilder(str);
- bulid.deleteCharAt(str.length()-1);
- return String.valueOf(bulid);
- }
- private static boolean areAllZero(boolean[] isZeroo){
- for(boolean b : isZeroo) if(!b) return false;
- return true;
- }
- static int indexof(char ch){
- int index="abcdefghijklmnopqrstuvwxyz".indexOf(ch);
- int index1="ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(ch);
- if(index<index1){
- return index1+1;
- }else{
- return index+1;
- }
- }
- static char[] shift(char[] array, int indexAlpha, int position) {
- int length=array.length;
- char temp;
- int j=position;
- char positionChar=array[position];
- boolean isFull=false;
- for(int i=position;i<indexAlpha+position;i++){
- if(j<length-1){
- temp=array[j];
- array[j]=array[j+1];
- array[j+1]=temp;
- j++;
- }else if(j==length){
- temp=array[j];
- array[j]=array[0];
- array[0]=temp;
- j++;
- }
- }
- return array;
- }
- }
- /*String str = "M1y java8 Progr5am";
- StringBuilder bulid = new StringBuilder(str);
- bulid.deleteCharAt(1); // Shift the positions front.
- bulid.deleteCharAt(8-1);
- bulid.deleteCharAt(15-2);
- System.out.println("Builder : "+bulid);
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement