Untitled
unknown
java
2 years ago
4.0 kB
3
Indexable
Never
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; public class Main { public static class Node { private int Habitantes; private Node next; Node(){ this.Habitantes = 0; this.next = null; } Node (int Habitantes){ this.Habitantes = Habitantes; this.next = null; } Node(int Habitantes, Node next){ this.Habitantes = Habitantes; this.next = next; } public int getHabitantes (){ return Habitantes; } public Node getNext (){ return next; } public void setNext(Node next) { this.next = next; } public void setHabitantes(int Habitantes) { this.Habitantes = Habitantes; } } public static class Lista { private Node head; private Node tail; public Lista () { this.head = null; this.tail = null; } public Node getHead(){ return head; } public void insertar(int v) { Node n_node = new Node(v, this.head); this.head = n_node; } public void insertarCola(int val){ Node nNode = new Node(val); if(this.head == this.tail && this.head == null){ this.head = this.tail = nNode; return; } else{ this.tail.setNext(nNode); this.tail = nNode; } } public Node remove(){ Node ret = this.head; if(this.head == null){return ret;} this.head = this.head.getNext(); return ret; } } public static boolean casaspal(List<Integer> arr, int N){ boolean palindromas = true; int mitadN = N/2; Lista listaHabitantes = new Lista (); Lista listaHabitantes2 = new Lista (); for(int i = 0; i < N;i++){ listaHabitantes.insertar(arr.get(i)); } for(int i = 0; i < N;i++){ listaHabitantes2.insertarCola(arr.get(i)); } for(int i = 1 ; i <= mitadN; i++){ System.out.println(mitadN); System.out.println(listaHabitantes.getHead().getHabitantes()); System.out.println(listaHabitantes2.getHead().getHabitantes()); System.out.println(listaHabitantes.getHead().getHabitantes() == listaHabitantes2.getHead().getHabitantes()); if(listaHabitantes.getHead().getHabitantes() - listaHabitantes2.getHead().getHabitantes() != 0){ palindromas = false; break; } listaHabitantes.remove(); listaHabitantes2.remove(); } return palindromas; } public static void main(String[] args) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); int N = Integer.parseInt(bufferedReader.readLine().trim()); List<Integer> arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) .map(Integer::parseInt) .collect(toList()); boolean espalindroma = Result.casaspal(arr, N); bufferedWriter.write(String.valueOf(espalindroma)); bufferedWriter.newLine(); bufferedReader.close(); bufferedWriter.close(); } }