강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

songsong song님의 프로필 이미지
songsong song

작성한 질문수

it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비

33. 3등의 성적은? (정렬 응용)

타임리밋 오류가 발생하는데 코드 한번만 봐주실 수 있을까요?

작성

·

175

0

#include <algorithm>
#include <functional>
#include <stdio.h>

using namespace std;

int main(){

     int n, a[101], cnt=0, result;
     scanf("%d", &n);
     for(int i=0; i<n; i++){
         scanf("%d", &a[i]);
     }

    sort(a, a+n, greater<>());

    
    for(int i=1; i<n; i++){
        int pre = a[i-1];
        int now = a[i];

        if(pre!=now){
            cnt++;
        }
        
        if(cnt == 2){
            printf("%d",now);
            exit(0);
        }
    }
     return 0;
}

답변 1

0

김태원님의 프로필 이미지
김태원
지식공유자

안녕하세요^^

제 컴퓨터에서는 정상적으로 100점이 나옵니다. 

songsong song님의 프로필 이미지
songsong song

작성한 질문수

질문하기