CSES - Datatähti 2018 alku - Results
Submission details
Task:Merkkijono
Sender:Leiska
Submission time:2017-10-03 13:53:29 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:42:9: error: expected ';' before 'if'
         if(check==input) {
         ^
input/code.cpp:46:9: error: 'else' without a previous 'if'
         else {
         ^

Code

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string input, check;

string checkstr(string str) {
    int pos, p = 0;
    int len, l = 1;
    int s = str.length();
    
    for(int i = 0; i<s; i++) {
        if (i>0 && str[i] == str[i-1]) {
            l++;
            if(l>len) {
                len = l;
                pos = p;
            }
        }
        else {
            l = 1;
            p = i;
        }
    }
    
    if (len <= 1) return str;
    else return str.erase(pos,len);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> input;
    
    int e = 0;
    while (e == 0) {
        check = checkstr(input)
        if(check==input) {
            cout << input << "\n";
            e=1;
        }
        else {
            input = check;
        }
    }
}