CSES - HIIT Open 2018 - Results
Submission details
Task:HIIT Generation
Sender:Lucinda
Submission time:2018-05-26 14:03:19 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.07 sdetails
#2--details
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.01 sdetails

Code

#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

void removeLetter(stack<int> &transf, stack<int> &letter) {
    int letter_id = letter.top();
    if (letter_id == 3) {
        transf.pop();
        letter.pop();
    } else {
        letter.pop();
        letter.push(letter_id + 1);
    }
}

int main() {
    int n;
    cin >> n;

    stack<int> transf;
    stack<int> letter;
    transf.push(-1);
    letter.push(0);

    char *c = new char[n];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    while (!transf.empty()) {
        int t_id = transf.top();
        int letter_id = letter.top();
        char c_to_be_printed;

        if (letter_id == 0) c_to_be_printed = 'H';
        else if (letter_id == 1 || letter_id == 2) c_to_be_printed = 'I';
        else c_to_be_printed = 'T';
        // cout << "t_id " << t_id << " letter " << c_to_be_printed << endl;

        bool addTransf = false;
        for (int next_t_id = t_id + 1; next_t_id < n; next_t_id++) {
            // cout << " trying to apply transform " << next_t_id << endl;
            if (c[next_t_id] == c_to_be_printed) { // if this transformation will apply to the letter
                // cout << "add transformation " << next_t_id << endl;
                removeLetter(transf, letter);
                transf.push(next_t_id);
                letter.push(0);
                addTransf = true;
                break;
            }
        }
        if (!addTransf) {
            // cout << "print ";
            cout << c_to_be_printed;
            removeLetter(transf, letter);
        }
    }
    cout << endl;

    delete[] c;
}

Test details

Test 1

Verdict: ACCEPTED

input
17
I
I
I
I
...

correct output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...

user output
HHHHHHHHHHHHHHHHHHIITHIITTHHII...

Test 2

Verdict:

input
333332
H
H
H
H
...

correct output
HIITIITIITIITIITIITIITIITIITII...

user output
(empty)

Test 3

Verdict: ACCEPTED

input
24
H
T
H
T
...

correct output
HIIHIITIIHIIHIITIIHIITIIHIIHII...

user output
HIIHIITIIHIIHIITIIHIITIIHIIHII...

Test 4

Verdict: ACCEPTED

input
0

correct output
HIIT

user output
HIIT