티스토리 뷰
- 층간소음
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
//freopen("input.txt", "rt", stdin);
int n, m, a, i, cnt=0, max=-2147000000;
scanf("%d %d", &n, &m);
for(i=0; i<n; i++){
scanf("%d", &a);
if(a>m) cnt++;
else cnt=0;
if(cnt>max) max=cnt;
if(max==0) max=-1;
}
printf("%d", max);
return 0;
}
- 분노유발자
- 내가푼코드
- 앞에서부터 확인
- 이중 for문을 쓰므로 효율적이지 않은 것 같음
- 앞에서부터 확인
- 내가푼코드
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
//freopen("input.txt", "rt", stdin);
int n, a, i, j, cnt, fire=0;
int h[101];
scanf("%d", &n);
for(i=1; i<=n; i++){
scanf("%d", &a);
h[i]=a;
}
for(i=1; i<n; i++){
cnt=0;
for(j=i+1; j<=n; j++){
if(h[i]>h[j]){
cnt++;
}
}
if(cnt==(n-i)){
fire++;
}
}
printf("%d", fire);
return 0;
}
- 다른코드
- 뒤에서부터 앞으로 큰 숫자가 있는지 확인
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
//freopen("input.txt", "rt", stdin);
int n, a, i, cnt=0, max;
int h[101];
scanf("%d", &n);
for(i=1; i<=n; i++){
scanf("%d", &a);
h[i]=a;
}
max=h[n];
for(i=n-1; i>=1; i--){
if(h[i]>max){
max=h[i];
cnt++;
}
}
printf("%d", cnt);
return 0;
}
'algorithm' 카테고리의 다른 글
[c++] 카드게임, 온도의 최대값 (0) | 2020.12.06 |
---|---|
[c++] 가위바위보 (0) | 2020.12.05 |
[c++] 아나그램, 선생님 퀴즈 (0) | 2020.12.03 |
[c++] 뒤집은 소수, 소수의 개수 (0) | 2020.12.01 |
[c++] 숫자의 총개수, 가장 많이 사용된 자리수 (0) | 2020.11.30 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 운영체제
- 구조체
- 교착상태
- 동적프로그래밍
- 재귀함수
- Stack
- react
- 세마포어
- 클래스
- client side rendering
- 배열
- 이진탐색
- BFS
- 스텍
- 최단경로
- C++
- dfs
- 인접리스트
- 소프트웨어
- 입출력장치
- Java
- stackframe
- C
- 퀵정렬
- 알고리즘
- javascript
- 병행프로세스
- 인접행렬
- 자료구조
- server side rendering
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함