Computer Programming Contest Preparation

ToolBox - Source for: 4/414/judged.cpp



/home/toolbox/public_html/solutions/4/414/judged.cpp
    1 #include <iostream>
    2 #include <vector>
    3 
    4 const int MAX_LINES = 255;
    5 
    6 int main(void)
    7 {
    8     int spaceCount[MAX_LINES];
    9     while(1)
   10         {
   11             int count;
   12             std::string line;
   13             std::cin >> count;
   14             std::getline(std::cin, line);
   15             if(count == 0)
   16                 break;
   17             int currentLine = 0;
   18             int minimum = 30;
   19             for(int x = 0; x < MAX_LINES; x++)
   20                 {
   21                     spaceCount[x] = 0;
   22                 }
   23             for(currentLine = 0; currentLine < count; currentLine++)
   24                 {
   25                     std::getline(std::cin, line);
   26                     for(int z = 0; z < line.length(); z++)
   27                         {
   28                             if(' ' == line[z])
   29                                 {
   30                                     spaceCount[currentLine]++;
   31                                 }
   32                         }
   33                     if(spaceCount[currentLine] < minimum)
   34                         minimum = spaceCount[currentLine];
   35                 }
   36             int sum = 0;
   37             for(int x = 0; x < count; x++)
   38                 {
   39                     sum += spaceCount[x] - minimum;
   40                 }
   41             std::cout << sum << std::endl;
   42             for(int x = 0; x < MAX_LINES; x++)
   43                 {
   44                     spaceCount[x] = 0;
   45                 }
   46         }
   47     return 0;
   48 }
   49