Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class me {
- public static void main(String[] args) throws IOException {
- Scanner s = new Scanner(new BufferedReader(new FileReader("DATA1.txt")));
- BufferedWriter bw = new BufferedWriter(new FileWriter("OUT1.txt"));
- for (int i = 0; i < 5; i++)
- {
- int numStacks = s.nextInt();
- int [] numPennies = new int [numStacks];
- int total = 0;
- for (int j = 0; j < numStacks; j++)
- {
- numPennies[j] = s.nextInt();
- total += numPennies[j];
- }
- int sizeStacks = total/numStacks;
- int totalDifferences = 0;
- for (int k = 0; k < numStacks; k++)
- {
- totalDifferences += Math.abs(sizeStacks - numPennies[k]);
- }
- int moves = totalDifferences / 2;
- if (i < 4)
- {
- bw.write(moves + "\n");
- }
- else
- {
- bw.write(moves + "");
- }
- }
- bw.close();
- }
- }
Add Comment
Please, Sign In to add comment