강의

멘토링

커뮤니티

Inflearn Community Q&A

wiseidea010610's profile image
wiseidea010610

asked

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

18. Inter-floor noise

18번 문제 3번 case에서 wrong으로 뜨는데 이유를 모르겠습니다.

Resolved

Written on

·

241

0

선생님 영상을 보기 전에 스스로 짠 코드인데, 선생님 것과는 else부분이 다릅니다. 3번 case에서 왜 안되는지 알려주실 수 있을까요?

int main() {
	freopen("input.txt", "rt", stdin);
	int n, m, i, num, cnt = 0, result=0;
	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%d", &num);
		if (num > m) {
			cnt++;
		}
		else {
			if (result <= cnt) {
				result = cnt;
			}
			cnt = 0;
		}
	}
	if (result == 0) printf("-1");
	else printf("%d", result);
	return 0;
}

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

Answer 2

1

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

다음입력을 가지고 디버그해보세요.

9 3

1 5 6 2 5 6 7 8 9 

답은 5입니다.

0

wiseidea010610님의 프로필 이미지
wiseidea010610
Questioner

감사합니다! 선생님 덕분에 해결하였습니다...!!!

wiseidea010610's profile image
wiseidea010610

asked

Ask a question