414 - Machined Surfaces

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
souravvv
New poster
Posts: 2
Joined: Wed Nov 25, 2015 5:49 am

414 - Machined Surfaces

Post by souravvv » Wed Feb 24, 2016 7:31 am

Hi. I have written a solution for this problem. It compiles and produces correct result in my computer. But on the OJ it says runtime error. Help me find the problem. My code is this:

Code: Select all

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long int ulli;
int main(){
   string s_n;
   ulli n,least;
   string temp;
   vector<string> data;
   vector <ulli> gap_data;
   ulli ans = 0;
   ulli current_gaps = 0;   
   while(getline(cin,s_n)){
      n = stoi(s_n);
      if(n == 0){
         cout << "" << endl;
      }
      else{
         while(n--){
            getline(cin,temp);
            for(ulli i = 0; i < 25; i++){
               if(temp[i]!= 'X'){
                  current_gaps++;
               }
            }
            gap_data.push_back(current_gaps);
            current_gaps = 0;
         }
         least = gap_data[0];
         for(ulli i = 1; i < gap_data.size(); i++){
            if(gap_data[i] < least){
               least = gap_data[i];
            }
         }
         for(ulli i = 0; i < gap_data.size(); i++){
            gap_data[i] = gap_data[i] - least;
         }
         for(ulli i = 0; i < gap_data.size(); i++){
            ans = ans + gap_data[i];
         }
         cout << ans << endl;
         ans = 0;
         gap_data.clear();
      }
   }
}
         

Post Reply

Return to “Volume 4 (400-499)”