#32018: 我不知道哪裡錯


noahyyds1995@gmail.com (krisarchie)


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int d = 0;
    sort(a, a + n);
    bool b = true;
    for(int i = 0; i < n - 1; i++){
        if(a[i] != a[i + 1] - 1){
            d = 0;
            break;
        }
        else{
            d = 1;
        }
    }
    for(int i = 0; i < n; i++){
            cout << a[i] << " ";
        }
    if (d == 1){
        cout << "yes";
    }
    else{
        cout << "no";        
    }
    
    return 0;
}

#32028: Re: 我不知道哪裡錯


yp11051026@yphs.tp.edu.tw (911-24吳秉儒)


#include
#include

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int d = 0;
    sort(a, a + n);
    bool b = true;
    for(int i = 0; i < n - 1; i++){
        if(a[i] != a[i + 1] - 1){
            d = 0;
            break;
        }
        else{
            d = 1;
        }
    }
    for(int i = 0; i < n; i++){
            cout << a[i] << " ";
        }
    if (d == 1){
        cout << "yes";
    }
    else{
        cout << "no";        
    }
    
    return 0;
}

只要輸出a[0]和a[n-1]就好了