#32018: 我不知道哪裡錯


noahyyds1995@gmail.com (krisarchie)

學校 : 臺北市立第一女子高級中學
編號 : 203692
來源 : [1.164.6.207]
最後登入時間 :
2023-01-07 00:57:50
c299. 1. 連號或不連號 -- 106學年度全國資訊學科能力競賽 | From: [220.135.17.72] | 發表日期 : 2022-09-07 19:16

#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吳秉儒)

學校 : 臺北市私立延平高級中學
編號 : 163548
來源 : [203.72.178.2]
最後登入時間 :
2024-04-29 10:25:26
c299. 1. 連號或不連號 -- 106學年度全國資訊學科能力競賽 | From: [1.171.226.117] | 發表日期 : 2022-09-08 20:47

#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]就好了

 
ZeroJudge Forum