강의

멘토링

커뮤니티

Inflearn Community Q&A

eagle11292602's profile image
eagle11292602

asked

Introduction to Algorithm Problem Solving for IT Employment (with C/C++): Coding Test Preparation

8. Correct parentheses (string control)

출력값이 항상 no로 나옵니다

Resolved

Written on

·

208

0

#include <stdio.h>

#include <string.h>

int main() {

char a[30];

int i,n,cnt=0;

n=strlen(a);

scanf("%s", &a);

for(i=0;i<n;i++){

if(a[i]=='(') cnt++;

else if(a[i]==')') cnt--;

if(cnt<0) break;

}

if(cnt==0) printf("YES\n");

else printf("NO\n");

return 0;

}

이렇게하면 왜 출력값이 항상 no로 나오는지 모르겠습니다

C++코테 준비 같이 해요!

Answer 1

1

a 배열에 괄호를 입력받기전에 a의 길이를 n에 넣어서 그렇네요

eagle11292602's profile image
eagle11292602

asked

Ask a question