답안 #364077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364077 2021-02-08T08:21:27 Z soba CONSUL (info1cup19_consul) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
//#include "grader.h"
#include "grader.cpp"

void solve(int n)
{
    int need=(n+2)/3;
    int arr[n+1];
    for(int i=1; i <= n ; i++)
    {
        arr[i]=(kth(i));
    }
    sort(arr+1, arr+n);
    int cn=1 , ans=-1;
    for(int i = 2 ; i<=n ; i++)
    {
        if(arr[i]==arr[i-1])cn++;
        else
        {
            if(n%3==0&&cn>need || cn>=need)
            {
                ans=arr[i-1];
                break;
            }
            cn=1;
        }
    }
    if(n%3==0&&cn>need || cn>=need)
            {
                ans=arr[n];
            }
    say_answer(ans);
}

Compilation message

consul.cpp: In function 'void solve(int)':
consul.cpp:13:5: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   13 |     sort(arr+1, arr+n);
      |     ^~~~
      |     std::sort
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from consul.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4887:5: note: 'std::sort' declared here
 4887 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
consul.cpp:20:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   20 |             if(n%3==0&&cn>need || cn>=need)
      |                ~~~~~~^~~~~~~~~
consul.cpp:28:14: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   28 |     if(n%3==0&&cn>need || cn>=need)
      |        ~~~~~~^~~~~~~~~