Editorial for Last Minute Preparations


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Türkçe

Tek bir kat parantezin içinde geçen yazılar bile paragraftan çıkarılacağı için kaç kat parantezin içinde olduğumuzu takip etmeliyiz. İç içe geçirilmiş üç noktalar istemediğimiz için bir parantez katından dışarı çıkarken de bu sırada kaç kat parantezin içinde olduğumuzu kontrol etmeli ve sadece artık hiçbir parantezin içinde değilsek üç nokta yazdırmalıyız.

English

As any text inside even a single layer of parentheses will be removed from the paragraph, we need to keep track of how many layers of parentheses we're deep in. Since we don't want to indent ellipses, we should also check how many layers of parentheses we're deep in as we exit a layer of parentheses and print ellipses only when we're not inside any layers of parentheses anymore.

Code

#include <stdio.h>

int main() {
    int length;
    scanf("%d ", &length);
    int depth = 0;
    for (int index = 0; index < length; index++)
    {
        int character = getchar();
        if (character == '(')
            depth++;
        if (depth == 0)
            printf("%c", character);
        if (character == ')')
        {
            depth--;
            if (depth == 0)
                printf("...");
        }
    }
    return 0;
}