/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'int main()':
foo.cc:59:19: error: expected primary-expression before '/' token
   59 |         cin >> N; /
      |                   ^
foo.cc:60:16: error: expected primary-expression before 'S'
   60 |         string S;
      |                ^
foo.cc:61:16: error: 'S' was not declared in this scope
   61 |         cin >> S;
      |                ^

Code

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int maxConsecutiveOnes(string s) {
    int maxCount = 0, currentCount = 0;
    vector<int> counts; 
    
    for (char c : s) {
        if (c == '1') {
            currentCount++;
        } else {
            if (currentCount > 0) {
                counts.push_back(currentCount);
                currentCount = 0;
            }
        }
    }
    if (currentCount > 0) {
        counts.push_back(currentCount); 
    }

    
    if (counts.empty()) return 0;

 
    int totalOnes = 0;
    for (int count : counts) {
        totalOnes += count; 
    }

    
    int maxConsecutive = 0;

    for (size_t i = 0; i < counts.size(); ++i) {
        maxConsecutive = max(maxConsecutive, counts[i]);
       
        if (i < counts.size() - 1) {
            maxConsecutive = max(maxConsecutive, counts[i] + counts[i + 1]);
        }
    }

    
    int numberOfFlips = (s.length() - totalOnes);
    
    if (numberOfFlips >= 1) {
        maxConsecutive = max(maxConsecutive, totalOnes + numberOfFlips);
    }

    return maxConsecutive;
}

int main() {
    int T;
    cin >> T; 
    while (T--) {
        int N;
        cin >> N; /
        string S;
        cin >> S; 

        
        int result = maxConsecutiveOnes(S);
        cout << result << endl; 
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1113 Fliping Game
Contest
Brain Booster #7
Language
C++11 (G++ 13.2.0)
Submit At
2024-11-05 15:02:10
Judged At
2024-11-05 15:02:10
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes