Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class PA {
- static ArrayList<Integer> data = new ArrayList<Integer>();
- public static void main(String[] args) throws FileNotFoundException {
- Scanner io = new Scanner(new File("test.txt"));
- while(io.hasNextInt())
- {
- int ss = io.nextInt();
- if(ss !=-1)
- data.add(ss);
- }
- for(int i=0;i<data.size();i++)
- {
- if(check(data.get(i).toString()))
- System.out.println(data.get(i));
- }
- }
- static boolean check(String p){
- StringBuffer d = new StringBuffer(p);
- if(d.toString().equals("4200"))
- {
- int x =3;
- x++;
- }
- // 1. case
- if(d.length()==1) return true;
- // 2.case
- if(d.length()>=2)
- {
- char ps = d.charAt(0);
- for(int i=1;i<d.length();i++)
- {
- if(ps!=d.charAt(i))
- {
- break;
- }
- else if(ps==d.charAt(i)&&i==(d.length()-1))
- {
- return true;
- }
- }
- }
- // 3.case
- if(d.length()>=3)
- {
- if((d.charAt(0)-d.charAt(1))<0)
- {
- for(int i=1;i<d.length();i++)
- {
- if(d.charAt(i)-d.charAt(i-1)!=1)
- {
- break;
- }
- else if((d.charAt(i)-d.charAt(i-1)==1)&&(i==d.length()-1))
- return true;
- }
- }else{
- for(int i=1;i<d.length();i++)
- {
- //int ct = d.charAt(i)-d.charAt(i-1);
- if( d.charAt(i)-d.charAt(i-1) !=-1)
- break;
- else if((d.charAt(i)-d.charAt(i-1)==-1)&&(i==d.length()-1))
- return true;
- }
- }
- }
- //4. case
- String cy = d.toString();
- String cx = d.reverse().toString();
- if(cx.equals(cy))
- return true;
- //5. case
- int number = Integer.parseInt(p);
- if(number%100==0)
- return true;
- if(d.length()==4)
- {
- int p1 = Integer.parseInt(d.substring(0,2));
- int p2 = Integer.parseInt(d.substring(2));
- if(p1==p2)
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement