티스토리 뷰

SW Expert Academy :: SWEA :: 5432 :: 쇠막대기 자르기


출처 : https://www.swexpertacademy.com/main/talk/codeBattle/problemDetail.do


#include <stdio.h>

#include <memory.h>
using namespace std;
 
char s[100001];
int a, n, l;
 
int main() {
    int T; scanf("%d", &T);
    for (int tc = 1; tc <= T; tc++) {
        scanf("%s", s); n = 0;a = 0; l = strlen(s);
        for (int i = 0; i < l; i++) {
            if (s[i] == '(') {
                if (s[i + 1] == ')') {
                    i++; a += n;
                }
                else {
                    a++; n++;
                }
            }
            else n--;
        }
        printf("#%d %d\n", tc, a);
    }
 
    return 0;
}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 5521] 상원이의 생일파티  (0) 2018.09.07
[SWEA 5436] 동욱이의 조판하기  (0) 2018.08.29
[SWEA 5431] 민석이의 과제 체크하기  (0) 2018.08.29
[SWEA 2382] 미생물 격리  (0) 2018.08.16
[SWEA 2383] 점심 식사시간  (2) 2018.08.16
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함