강의

멘토링

커뮤니티

Inflearn Community Q&A

kuku's profile image
kuku

asked

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

23. Continuous partial increasing sequence

괄호 질문 있습니다.

Written on

·

257

0

#include <stdio.h>

int main() {

freopen("input.txt", "rt", stdin);

int n, i, pre, now, cnt, max;

scanf("%d", &n);

scanf("%d", &pre); //메커니즘은 pre와 now를 비교하여 cnt를 증가시키는 방법이다. 따라서 배열의 맨처음의 원소값이 있어야 비교가능.  

cnt=1;

max=1;

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

scanf("%d", &now);

if(now>=pre){

cnt++;

if(cnt>max){

max = cnt;

}

}else{

cnt=1;

pre=now;

}

}

printf("%d\n", max);

return 0;

}

단지 else부분에 괄호만 쳤는데 답이 7이 나오는게 이해가 되질 않습니다. 왜 그럴까요? ㅠㅠ

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

Answer 2

1

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

pre=now 문은 if문과 상관없이 for문이 돌면서 계속 해주어야 합니다.

0

kuku님의 프로필 이미지
kuku
Questioner

아하... 감사합니다. 강의 잘듣고 있어요!

kuku's profile image
kuku

asked

Ask a question