CSES - Datatähti 2018 alku - Results
Submission details
Task:Merkkijono
Sender:eliaskosunen
Submission time:2017-10-03 18:21:11 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.03 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.04 sdetails
#6ACCEPTED0.05 sdetails
#7ACCEPTED0.03 sdetails
#8ACCEPTED0.04 sdetails
#9ACCEPTED0.05 sdetails
#10ACCEPTED0.05 sdetails

Code

#include <iostream>
#include <string>
#include <vector>

template <typename InputIt>
std::string remove(InputIt str_begin, InputIt begin, InputIt end) {
    std::string str;
    auto prefix_len = std::distance(str_begin, begin);
    if (prefix_len > 0) {
        str.reserve(std::distance(str_begin, begin));
        str.assign(str_begin, begin);
    }

    auto it = begin;
    while (begin != end && *begin == *it) {
        ++begin;
    }
    if (std::distance(str_begin, end) == 0) {
        return str;
    }
    str.append(begin, end);

    return str;
}

int main() {
    std::string str;
    std::cin >> str;

    for (auto it = str.begin() + 1; it != str.end() && !str.empty(); ++it) {
        /* std::cout << str << ", it: " << *it << ", prev: " << *(it - 1) */
        /*           << ", dist: " << std::distance(str.begin(), it) << '\n'; */
        if (*it == *(it - 1)) {
            str = remove(str.begin(), it - 1, str.end());
            it = str.begin();
        }
    }
    std::cout << str << '\n';
}

Test details

Test 1

Verdict: ACCEPTED

input
ABABABABABABABABABABABABABABAB...

correct output
ABABABABABABABABABABABABABABAB...

user output
ABABABABABABABABABABABABABABAB...

Test 2

Verdict: ACCEPTED

input
AABBAABBAABBAABBAABBAABBAABBAA...

correct output
(empty)

user output
(empty)

Test 3

Verdict: ACCEPTED

input
ABABABABABABABABABABABABABABAB...

correct output
(empty)

user output
(empty)

Test 4

Verdict: ACCEPTED

input
BBABABBBBBAABBBABABABBBBAAABAB...

correct output
BAB

user output
BAB

Test 5

Verdict: ACCEPTED

input
ACDCBBACDBBBACAACBBDBADBAABABA...

correct output
ACDCACDADBADABACACDCADADABABCA...

user output
ACDCACDADBADABACACDCADADABABCA...

Test 6

Verdict: ACCEPTED

input
EETFHIJOGACDHMGVFJCMETMZDEITTR...

correct output
TFHIJOGACDHMGVFJCMETMZDEIROTET...

user output
TFHIJOGACDHMGVFJCMETMZDEIROTET...

Test 7

Verdict: ACCEPTED

input
GOONLAHLYPRFCZKIKSJWAWWYJJPCDB...

correct output
GNLAHLYPRFCZKIKSJWAYPCDNWYMRCE...

user output
GNLAHLYPRFCZKIKSJWAYPCDNWYMRCE...

Test 8

Verdict: ACCEPTED

input
PISHWMOTCDDZFRMYMOMYDYYGJZIQHS...

correct output
PISHWMOTCZFRMYMOMYDGJZIQHSVAOK...

user output
PISHWMOTCZFRMYMOMYDGJZIQHSVAOK...

Test 9

Verdict: ACCEPTED

input
QUVVTPXAMWWODFXRONJODPGBTCISGM...

correct output
QUTPXAMODFXRONJODPGBTCISGMVRBW...

user output
QUTPXAMODFXRONJODPGBTCISGMVRBW...

Test 10

Verdict: ACCEPTED

input
POXHAHYEZTLYNFSLABODMRNKDSKROZ...

correct output
POXHAHYEZTLYNFSLABODMRNKDSKROZ...

user output
POXHAHYEZTLYNFSLABODMRNKDSKROZ...