Jayakrishna14

Falling footballs Java

Jun 14th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.     static int[] arr = new int[71];
  6.     final static int OFFSET = 25;
  7.     static Scanner sc;
  8.  
  9.     public static void fillArray(int n){
  10.         while(n-- > 0){
  11.             int index = OFFSET + sc.nextInt();
  12.             while(arr[index] > arr[index + 1]) index++;
  13.             while(arr[index] > arr[index - 1]) index--;
  14.             arr[index]++;
  15.         }
  16.     }
  17.  
  18.     public static void print() {
  19.         int start = 0;
  20.         while(arr[start] == 0) start++;
  21.         int last = 70;
  22.         while(arr[last] == 0) last--;
  23.         int max = 0;
  24.         for(int i=start; i<=last; i++) max = Math.max(max, arr[i]);
  25.  
  26.         while(max > 0){
  27.             for(int i=start; i<=last; i++){
  28.                 if(arr[i] == max){
  29.                     System.out.print('O');
  30.                     arr[i]--;
  31.                 } else {
  32.                     System.out.print('.');
  33.                 }
  34.             }
  35.             System.out.println();
  36.             max--;
  37.         }
  38.     }
  39.  
  40.     public static void main(String[] args) {
  41.         sc = new Scanner(System.in);
  42.         int Q = sc.nextInt();
  43.         for(int i=1; i<=Q; i++) {
  44.             System.out.println("Case " + i + ":");
  45.             fillArray(sc.nextInt());
  46.             print();
  47.         }
  48.         sc.close();
  49.     }
  50. }
Tags: Java
Advertisement
Add Comment
Please, Sign In to add comment