Advertisement
Guest User

BABBLING BROOKS

a guest
Jan 26th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4. public class BabblingBrooks{
  5.  
  6.   //between 1 and 100 streams, each with an individual flow
  7.   //streams may join up or split
  8.   public static void main(String []args){
  9.    
  10.     ArrayList<Integer> streams= new ArrayList<Integer>();
  11.     Scanner s= new Scanner(System.in);
  12.     int initialNum= s.nextInt();
  13.    
  14.     for(int i=0; i< initialNum; i++){
  15.      streams.add(s.nextInt());
  16.     }
  17.    
  18.     while(true){
  19.      int streamNum= streams.size();
  20.      int decide= s.nextInt();
  21.    
  22.      if(decide==77)//finished
  23.        break;
  24.      
  25.      else if(decide==99){//split a stream
  26.       int splitNum=s.nextInt();
  27.       int leftPercent=s.nextInt();
  28.      
  29.       int originalFlow=streams.get(splitNum-1);
  30.       streams.set(splitNum-1,(int) (originalFlow* leftPercent/100));
  31.       streams.add(streams.get(streamNum-1));
  32.      
  33.       for(int i=streamNum-2; i>=splitNum; i--)
  34.       {
  35.         streams.set(i+1,streams.get(i));
  36.       }
  37.       streams.set(splitNum,(int)(originalFlow*(100-leftPercent)/100));
  38.      
  39.      }
  40.      
  41.      else if(decide==88){//join two streams
  42.      
  43.       int joinNum=s.nextInt();
  44.       streams.set(joinNum-1, streams.get(joinNum-1)+streams.get(joinNum));
  45.      
  46.       for(int i=joinNum; i<streamNum-1; i++){
  47.         streams.set(i, streams.get(i+1));
  48.       }
  49.       streams.remove(streamNum-1);
  50.      }
  51.      
  52.     }
  53.    
  54.     for(int hitlerDidNothingWrong: streams){
  55.      System.out.println(hitlerDidNothingWrong);
  56.     }
  57.                
  58.   }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement