Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class PA {
  4.     static ArrayList<Integer> data = new ArrayList<Integer>();
  5.     public static void main(String[] args) throws FileNotFoundException {
  6.         Scanner io = new Scanner(new File("test.txt"));
  7.         while(io.hasNextInt())
  8.             {
  9.             int ss = io.nextInt();
  10.             if(ss !=-1)
  11.             data.add(ss);
  12.             }
  13.        
  14.         for(int i=0;i<data.size();i++)
  15.         {
  16.             if(check(data.get(i).toString()))
  17.                 System.out.println(data.get(i));
  18.         }
  19.     }
  20.     static boolean check(String p){
  21.         StringBuffer d = new StringBuffer(p);
  22.         if(d.toString().equals("4200"))
  23.         {
  24.           int x =3;
  25.           x++;
  26.         }
  27.         // 1. case
  28.         if(d.length()==1) return true;
  29.         // 2.case
  30.         if(d.length()>=2)
  31.         {
  32.             char ps = d.charAt(0);
  33.             for(int i=1;i<d.length();i++)
  34.             {
  35.                 if(ps!=d.charAt(i))
  36.                 {
  37.                     break;
  38.                 }
  39.                 else if(ps==d.charAt(i)&&i==(d.length()-1))
  40.                 {
  41.                     return true;
  42.                 }
  43.             }
  44.         }
  45.         // 3.case
  46.  
  47.         if(d.length()>=3)
  48.         {
  49.             if((d.charAt(0)-d.charAt(1))<0)
  50.             {
  51.                 for(int i=1;i<d.length();i++)
  52.                 {
  53.                     if(d.charAt(i)-d.charAt(i-1)!=1)
  54.                     {
  55.                         break;
  56.                     }
  57.                     else if((d.charAt(i)-d.charAt(i-1)==1)&&(i==d.length()-1))
  58.                         return true;
  59.                 }
  60.             }else{
  61.                 for(int i=1;i<d.length();i++)
  62.                 {
  63.                     //int ct = d.charAt(i)-d.charAt(i-1);
  64.                     if( d.charAt(i)-d.charAt(i-1) !=-1)
  65.                         break;
  66.                     else if((d.charAt(i)-d.charAt(i-1)==-1)&&(i==d.length()-1))
  67.                         return true;
  68.                 }
  69.             }
  70.         }
  71.         //4. case
  72.         String cy = d.toString();
  73.         String cx = d.reverse().toString();
  74.        
  75.         if(cx.equals(cy))
  76.             return true;
  77.         //5. case
  78.        
  79.         int number = Integer.parseInt(p);
  80.         if(number%100==0)
  81.             return true;
  82.         if(d.length()==4)
  83.         {
  84.             int p1 = Integer.parseInt(d.substring(0,2));
  85.             int p2 = Integer.parseInt(d.substring(2));
  86.             if(p1==p2)
  87.                 return true;
  88.         }
  89.         return false;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement