Jacob_Thomas

Untitled

Jun 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MagicWrd {
  4.     public static void main(String args[]) {
  5.         Scanner sc=new Scanner(System.in);
  6.         int n=sc.nextInt();
  7.          int primes[]= {67,71,73,79,83,89};
  8.         int counter=0;
  9.         int primes1[]={97,101,103,107,109,113};
  10.         while(counter<n)
  11.         {
  12.             int length=sc.nextInt();
  13.             String s1=sc.nextLine();
  14.             String s=sc.nextLine();
  15.             outer:
  16.             for(int x=0;x<length;x++)
  17.             {
  18.                 int c=s.charAt(x);
  19.                 int min=500;
  20.                 int diff=0;
  21.                 if(c>=0&&c<=90)
  22.                 {
  23.                 for(int y=0;y<6;y++)
  24.                 {
  25.                     if(c==primes[y])
  26.                     {
  27.                        
  28.                     System.out.print((char)c);
  29.                     continue outer;}
  30.                     diff=c>primes[y]?c-primes[y]:primes[y]-c;
  31.                     if(diff<min)
  32.                     {
  33.                         min=diff;
  34.                     }
  35.                 }
  36.                
  37.                 int top=c+min;
  38.                 int bottom=c-min;
  39.                 if(bottom==67||bottom==71||bottom==73||bottom==79||bottom==83||bottom==89)
  40.                 {
  41.                     System.out.print((char)bottom);
  42.                 }else
  43.                 System.out.print((char)top);
  44.             }
  45.             else
  46.             {
  47.                 for(int y=0;y<6;y++)
  48.                 {
  49.                     if(c==primes1[y])
  50.                     {
  51.                        
  52.                     System.out.print((char)c);
  53.                     continue outer;}
  54.                     diff=c>primes1[y]?c-primes1[y]:primes1[y]-c;
  55.                     if(diff<min)
  56.                     {
  57.                         min=diff;
  58.                     }
  59.                 }
  60.                
  61.                 int top=c+min;
  62.                 int bottom=c-min;
  63.                 if(bottom==97||bottom==101||bottom==103||bottom==107||bottom==109||bottom==113)
  64.                 {
  65.                     System.out.print((char)bottom);
  66.                 }else
  67.                 System.out.print((char)top);
  68.            
  69.             }
  70.            continue;
  71.         }
  72.            
  73.             counter=counter+1;
  74.             System.out.println();
  75.            
  76.         }
  77.        
  78.        
  79.        
  80.        
  81.        
  82.        
  83.        
  84.     }}
Add Comment
Please, Sign In to add comment