Advertisement
Guest User

salivA

a guest
Aug 30th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1.     import java.io.*;
  2.     import java.math.* ;
  3.      class  Main
  4.      {    
  5.  
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.     BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
  9.     String line =bi.readLine();
  10.     int i = Integer.parseInt(line);
  11.     int key;
  12.     int l;char c;
  13.     int f;
  14.     while(i!=0){
  15.         i--;
  16.         key = Integer.parseInt(bi.readLine());
  17.         line = bi.readLine();
  18.         for(l=0;l<line.length();l++){
  19.             char d = line.charAt(l);
  20.             if(d=='.'){
  21.                 System.out.print(" ");
  22.                 continue;
  23.             }
  24.             if(key<26){
  25.  
  26.                     if(d>96){
  27.                         f = key ;
  28.                             if(d+f>122){
  29.                                 d = (char)(96 +  f   - (122-d));
  30.                             }
  31.                             else {
  32.                                 d = (char)(d + f);
  33.                             }
  34.                         }
  35.  
  36.                     else{
  37.                         f = key ;
  38.                         if(d+f>90){
  39.                                 d = (char)(64 +  f   - (90-d));
  40.                             }
  41.                         else {
  42.                                 d = (char)(d + f);
  43.                             }
  44.                         }
  45.                     }
  46.             else{
  47.                
  48.                     if(d>96){
  49.                         f = key - 26;
  50.                             if(d+f>122){
  51.                                 d = (char)(96 +  f   - (122-d));
  52.                             }
  53.                             else {
  54.                                 d = (char)(d + f);
  55.                             }
  56.                         d =Character.toUpperCase(d);
  57.                        
  58.                     }
  59.  
  60.                     else{
  61.                         f = key -26;
  62.                             if(d+f>90){
  63.                                 d = (char)(64 +  f   - (90-d));
  64.                             }
  65.                             else {
  66.                                 d = (char)(d + f);
  67.                             }
  68.                         d = Character.toLowerCase(d);
  69.                     }
  70.                 }
  71.  
  72.                
  73.                 System.out.print(d);   
  74.                 }
  75.  
  76.                 System.out.println();
  77.     }
  78.  
  79.  
  80.  
  81.     }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement