Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. public class anelidos{
  2.     public static void main(String [] args )
  3.     {
  4.         int n;
  5.         String s,temp;
  6.         Scanner sc=new Scanner(System.in);
  7.         n=sc.nextInt();
  8.         while( n>0 && sc.hasNext());
  9.        {
  10.            
  11.            
  12.             s=sc.next();
  13.             s=s.substring(0,s.length()-1);
  14.             for(int i=0;i<n;i++)
  15.             {  
  16.                
  17.                     temp=s;
  18.                     temp=temp.replace('N', 'K');
  19.                     temp=temp.replace('A', 'N');
  20.                     temp=temp.replace('K', 'A');
  21.                    // System.out.println(s);
  22.                     s=s+reverse(temp);
  23.                
  24.                
  25.             }
  26.             System.out.println(s+"C");
  27.             n=sc.nextInt();
  28.         }
  29.  
  30.     }
  31.     public static String reverse(String s)
  32.     {
  33.         int left=0,right=s.length()-1;
  34.        char[]a= s.toCharArray();
  35.        char temp;
  36.         while(left<right)
  37.         {
  38.             temp=a[left];
  39.             a[left]=a[right];
  40.             a[left]=temp;  
  41.             left++;
  42.             right--;
  43.         }
  44.         return new String(a);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement