Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HeapSort {
- private static int N;
- public static void sort(double arr[]){
- heapify(arr);
- for (int i = N; i > 0; i--){
- swap(arr,0, i);
- N = N-1;
- maxheap(arr, 0);
- }
- }
- public static void heapify(double arr[]){
- N = arr.length-1;
- for (int i = N/2; i >= 0; i--)
- maxheap(arr, i);
- }
- public static void maxheap(double arr[], int i){
- int left = 2*i ;
- int right = 2*i + 1;
- int max = i;
- if (left <= N && arr[left] > arr[i])
- max = left;
- if (right <= N && arr[right] > arr[max])
- max = right;
- if (max != i){
- swap(arr, i, max);
- maxheap(arr, max);
- }
- }
- public static void swap(double arr[], int i, int j){
- double tmp = arr[i];
- arr[i] = arr[j];
- arr[j] = tmp;
- }
- public static void main(String[] args){
- Scanner scan = new Scanner( System.in );
- int n = scan.nextInt();
- double aux[] = new double [n];
- for(int k = 0; k < n; k++){
- aux[k] = Double.parseDouble(scan.next());
- }
- /* cuantas operaciones bancarias desea realiza */
- int operaciones=scan.nextInt();
- int cliente1;
- int cliente2;
- double monto;
- for (int t= 0;t<operaciones;t++){
- String operacion=scan.next();
- if (operacion.equals("consultar")){
- double sumaT=0;
- cliente1=scan.nextInt();
- cliente2=scan.nextInt();
- int count=cliente1-1;
- double tempor[]=new double [(cliente2-cliente1)+1];
- for(int i=0;i<tempor.length;i++,count++){
- tempor[i]=aux[count];
- sumaT=sumaT+tempor[i];
- }
- for(int i=0;i<tempor.length;i++){
- System.out.print("(");
- System.out.print(tempor[i]+"");
- System.out.print(")");
- }
- System.out.println();
- sumaT=sumaT/tempor.length;
- sumaT=(double)Math.round(sumaT*10)/10;
- sort(tempor);
- System.out.println(tempor[0]+" "+tempor[tempor.length-1] +" "+ String.format("%.1f", sumaT));
- continue;
- }
- else if(operacion.equals("retirar")){
- cliente1=scan.nextInt();
- monto=Double.parseDouble(scan.next());
- aux[cliente1-1] = aux[cliente1-1]-monto;
- continue;
- }
- else if(operacion.equals("depositar")){
- cliente1=scan.nextInt();
- monto=Double.parseDouble(scan.next());
- aux[cliente1-1] = aux[cliente1-1]+ monto;
- continue;
- }
- else{ continue;}
- }
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement