UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211984#3818. 01游戏PanjunnanCompile Error//C++1.2kb2024-10-13 09:36:062024-10-13 12:39:25

answer

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int calculateValue(const string &s) {
    int maxValue = 1;
    int currentValue = 1;
    
    for (size_t i = 1; i < s.size(); ++i) {
        if (s[i] != s[i - 1]) {
            currentValue++;
        } else {
            maxValue = max(maxValue, currentValue);
            currentValue = 1;
        }
    }
    maxValue = max(maxValue, currentValue);

    return maxValue;
}

void ddd(string &s, vector<int> &U) {
    sort(U.rbegin(), U.rend()); 
    for (int x : U) {
        if (x > 0) {
            for (int i = 0; i < x; ++i) {
                s[i] = (s[i] == '0') ? '1' : '0';
            }
            for (int i = x; i < s.size(); ++i) {
                s[i] = (s[i] == '0') ? '1' : '0';
            }
        } else if (x == 0) {

            for (char &c : s) {
                c = (c == '0') ? '1' : '0';
            }
        }
    }
}

int main() {
    string s;
    cin >> s; 
    int n = s.length();
    vector<int> U; 
    if (n > 0) U.push_back(n);
    ddd(s, U);
    int value = calculateValue(s);
    cout << value << endl;
    
    return 0;
}

Details

answer.code: In function 'void ddd(std::string&, std::vector<int>&)':
answer.code:25:18: error: range-based 'for' loops are not allowed in C++98 mode
     for (int x : U) {\x0d
                  ^
answer.code:35:28: error: range-based 'for' loops are not allowed in C++98 mode
             for (char &c : s) {\x0d
                            ^