Computer Programming Contest Preparation

ToolBox - Source for: 4/414/Main.java



/home/toolbox/public_html/solutions/4/414/Main.java
    1 /*
    2 Jason
    3 Judged correctly on 20090909
    4 */
    5 
    6 import java.util.Scanner;
    7 import java.util.ArrayList;
    8 
    9 public class Main
   10 {
   11 
   12     public static void main(String[] args)
   13     {
   14         Scanner in = new Scanner(System.in);
   15         int count = in.nextInt();
   16 
   17         while (count != 0)
   18             {
   19                 // advance the scanner line token
   20                 in.nextLine();
   21                 // holds the counts of the spaces for the lines
   22                 ArrayList<Integer> lineCounts = new ArrayList<Integer>();
   23                 // instance var holds lowest number spaces for given set
   24                 int lowestNumberSpaces = Integer.MAX_VALUE;
   25                 // for each line
   26                 for (int c = 0; c < count; c++)
   27                     {
   28                         // get the next line
   29                         String line = in.nextLine();
   30                         // instance var holds the number of spaces in current line
   31                         int spaces = 0;
   32                         // for each character in line, check for spaces
   33                         for (int x = 0; x < line.length(); x++)
   34                             {
   35                                 if (' ' == line.charAt(x))
   36                                     {
   37                                         spaces++;
   38                                     }
   39                             }
   40                         // put the spaces data in the lineCounts
   41                         lineCounts.add(c, spaces);
   42                         // if this line has the lowest number of spaces, then set
   43                         if (spaces < lowestNumberSpaces)
   44                             {
   45                                 lowestNumberSpaces = spaces;
   46                             }
   47                     }
   48                 int totalSpaces = 0;
   49                 for (int c = 0; c < count; c++)
   50                     {
   51                         totalSpaces = totalSpaces + lineCounts.get(c) - lowestNumberSpaces;
   52                     }
   53                 System.out.println(totalSpaces);
   54                 // advance to next input set
   55                 count = in.nextInt();
   56             }
   57     }
   58 }
   59 
   60