Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package holaM;
- import java.util.*;
- public class Antenas {
- static class Lista<T> {
- static class NodoLista<T> {
- NodoLista anterior;
- NodoLista siguiente;
- T valor;
- public NodoLista(T valor) {
- this.valor = valor;
- siguiente = anterior = null;
- }
- }
- NodoLista<T> frente;
- NodoLista<T> cola;
- int longitud;
- public Lista() {
- frente = cola = null;
- longitud = 0;
- }
- public void insertarFrente(T valor) {
- NodoLista<T> nodo = new NodoLista<>(valor);
- if (longitud == 0) {
- cola = nodo;
- } else {
- frente.anterior = nodo;
- nodo.siguiente = frente;
- }
- frente = nodo;
- longitud++;
- }
- public void insertarCola(T valor) {
- if (longitud == 0) {
- insertarFrente(valor);
- } else {
- NodoLista<T> nodo = new NodoLista<>(valor);
- cola.siguiente = nodo;
- nodo.anterior = cola;
- cola = nodo;
- longitud++;
- }
- }
- public void insertar(T valor, int posicion) {
- if (posicion < 0 || posicion > longitud) {
- throw new IllegalArgumentException("posicion "+posicion+" fuera de rango [0, "+longitud+"]");
- }
- if (posicion == 0) {
- insertarFrente(valor);
- }
- else if (posicion == longitud) {
- insertarCola(valor);
- }
- else {
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++) {
- ref = ref.siguiente;
- }
- NodoLista<T> nodo = new NodoLista<>(valor);
- nodo.siguiente = ref;
- nodo.anterior = ref.anterior;
- ref.anterior.siguiente = nodo;
- ref.anterior = nodo;
- longitud++;
- }
- }
- public T removerFrente() {
- if (longitud == 0) {
- return null;
- }
- T valor = frente.valor;
- frente = frente.siguiente;
- longitud--;
- if (longitud > 0) {
- frente.anterior = null;
- }
- return valor;
- }
- public void borrarcola(){
- while ( frente != null) {
- frente = frente.siguiente;
- longitud--;
- }
- }
- public T removerCola() {
- if (longitud == 0) {
- return null;
- }
- T valor = cola.valor;
- cola = cola.anterior;
- longitud--;
- if (longitud > 0) {
- cola.siguiente = null;
- }
- return valor;
- }
- public T remover(int posicion) {
- if (posicion < 0 || posicion >= longitud) {
- throw new IllegalArgumentException("posicion "+posicion+" fuera de rango [0, "+longitud+")");
- }
- if (posicion == 0) {
- return removerFrente();
- }
- if (posicion == longitud-1) {
- return removerCola();
- }
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++) {
- ref = ref.siguiente;
- }
- T valor = ref.valor;
- ref.anterior.siguiente = ref.siguiente;
- ref.siguiente.anterior = ref.anterior;
- longitud--;
- return valor;
- }
- public T valorEn(int posicion) {
- if (posicion < 0 || posicion >= longitud) {
- throw new IllegalArgumentException("posicion "+posicion+" fuera de rango [0, "+longitud+")");
- }
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.valor;
- }
- public T obtenerFrente() {
- if (longitud == 0) {
- return null;
- }
- return frente.valor;
- }
- public T obtenerCola() {
- if (longitud == 0) {
- return null;
- }
- return cola.valor;
- }
- public int indiceDe(T valor) {
- NodoLista<T> ref = frente;
- for (int i = 0; i < longitud; i++, ref = ref.siguiente) {
- if (ref.valor.equals(valor)) {
- return i;
- }
- }
- return -1;
- }
- public boolean contiene(T valor) {
- return indiceDe(valor) != -1;
- }
- public int longitud() {
- return longitud;
- }
- }
- public static void main(String args[]) {
- Scanner teclado= new Scanner(System.in);
- Lista<Integer> lista = new Lista<>();
- //System.out.println("Digite el numero de casos ");
- short casos = teclado.nextShort();
- while(casos>0){
- //System.out.println(" Digite el numero de antenas ");
- int antenas = teclado.nextInt();
- int rango;
- //for ( int i=0;i<lista.longitud;i++){lista.remover(i);}
- while (antenas>0){
- rango=teclado.nextInt();
- lista.insertarCola(rango);
- antenas--;
- }
- for ( int n=0;n<lista.longitud;n++){
- int count=0;
- if (n==0){
- System.out.print(count+1+" ");
- continue;
- }
- for (int i=n;i>=0;i--){
- if (i==n){continue;
- }
- //System.out.println("valor en i "+i);
- if(lista.valorEn(i)>lista.valorEn(n) ){
- break;
- }
- if(lista.valorEn(i)<=lista.valorEn(n) ){
- //System.out.println("valor en"+lista.valorEn(n)+" "+lista.valorEn(i)+"**"+n);
- count=count+1;
- }
- }
- //System.out.println("este es el contador "+count);
- System.out.print(count+1+" ");
- }
- lista.borrarcola();
- casos--;
- System.out.println();
- }
- //System.out.println(" frente y cola "+lista.obtenerCola()+" "+lista.obtenerFrente());
- teclado.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement