백준

백준 13627 위험한 다이빙 c++

2024. 4. 10. 21:13

 

 

 

처음 작성한 코드는 다음과 같다.

몇 테스트 케이스는 통과되었고, 

몇 테스트 케이스는 실패가 떴다.

#include <iostream>
using namespace std;

int main(){
    int n,r;
    cin >> n >> r;
    
    int temp;
    bool arr[r+1]={false, };
    for(int i=1; i<=r; i++){
        cin >> temp;
        arr[temp] = true;
    }
        
    if(r==n){
        cout << "*";
    }
    else{
        for(int i=1; i<=r; i++){
            if(arr[i]==false)
                cout << i << " ";
        }
    }
    
    return 0;
}
#include <iostream>
using namespace std;

int main(){
    
    //입력
    int n,r;
    cin >> n >> r;
    
    int temp;
    bool arr[n+1]={false, };
    for(int i=1; i<=r; i++){
        cin >> temp;
        arr[temp] = true;
    }
    
    // arr배열 확인해 어떻게 출력할지 결정
    int count = 0;
    for(int i=1; i<=n; i++){
        if(arr[i]==true)
            count++;
    }    
    
    bool all;
    if(count==n)
        all = true;
    else
        all = false;
        
    //출력
    if(all){
        cout << "*";
    }
    else{
        for(int i=1; i<=r; i++){
            if(arr[i]==false)
                cout << i << " ";
        }
    }
    
    return 0;
}

 

 

 

수정해봤지만 틀렸다는 결과가 나왔다.

다시 도전해 봐야겠다.

#include <iostream>
using namespace std;

int main(){
    int n,r;
    cin >> n >> r;
    
    bool arr[10001]={false, };
    for(int i=1; i<=r; i++){
        int temp;
        cin >> temp;
        arr[temp] = true;
    }
        
    if(r==n){
        cout << "*";
    }
    else{
        for(int i=1; i<=r; i++){
            if(arr[i]==false)
                cout << i << " ";
        }
    }
    
    return 0;
}

 

 

 

 

 

'백준' 카테고리의 다른 글

백준 14889 스타트와 링크 c++  (0) 2024.04.11
백준 15059 Hard choice c++  (0) 2024.04.09
백준 16967 배열 복원하기 c++  (0) 2024.04.08
백준 20922 겹치는 건 싫어 c++  (0) 2024.04.07
백준 8979 올림픽 c++  (0) 2024.04.06