Advertisement
Guest User

ED121

a guest
Feb 25th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class ED121{
  4.   static String format(String s){
  5.     return s.replaceAll("\\W", "").replaceAll("\\d", "").toLowerCase();
  6.   }
  7.  
  8.   static void palindrome(String s){
  9.     s = format(s);
  10.  
  11.     String reverse = "";
  12.  
  13.     for(int i = s.length() - 1; i >= 0; i--)
  14.       reverse = reverse + s.charAt(i);
  15.  
  16.     if(s.equals(reverse))
  17.       System.out.println("sim");
  18.     else
  19.       System.out.println("nao");
  20.   }
  21.  
  22.   public static void main(String[] args){
  23.     Scanner stdin = new Scanner(System.in);
  24.  
  25.     int n = stdin.nextInt();
  26.     stdin.nextLine();
  27.  
  28.     System.out.println(n);
  29.  
  30.     for(int i = 0; i < n; i++){
  31.       String s = stdin.nextLine();
  32.       palindrome(s);
  33.     }
  34.  
  35.     stdin.close();
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement