#include <stdio.h>
#include <stdlib.h>
void bubble_sort(int *A,int n) {
int i,chair,done;
do {
done=1;
for (i=1;i<n;i++) {
if (A[i]>A[i+1]) {
chair=A[i];
A[i]=A[i+1];
A[i+1]=chair;
done=0;
}
}
} while (!done);
}
int main() {
int *L,*S,n,i,j,height,islands,maxislands,sealevel,minl,maxl;
scanf("%d",&n);
L=(int*)calloc(n+1,sizeof(int));
S=(int*)calloc(n+1,sizeof(int));
scanf("%d",L+1);
minl=L[1]; maxl=L[1];
S[1]=L[1];
for (i=2;i<=n;i++) {
scanf("%d",L+i);
if (L[i]<minl) minl=L[i];
else if (L[i]>maxl) maxl=L[i];
S[i]=L[i];
}
bubble_sort(S,n);
maxislands=0;
for (i=0;i<=n;i++) {
sealevel=S[i];
if (n-i<=maxislands) break;
else {
islands=0;
for (j=1;j<=n;j++) {
if (L[j]>sealevel && L[j-1]<=sealevel) {
islands++;
}
}
if (islands>maxislands) maxislands=islands;
}
}
printf("%d\n",maxislands);
}
컴파일 시 표준 에러 (stderr) 메시지
gw.c: In function 'main':
gw.c:21:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d",&n);
| ^~~~~~~~~~~~~~
gw.c:24:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%d",L+1);
| ^~~~~~~~~~~~~~~
gw.c:28:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d",L+i);
| ^~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |