Submission

Status:
PPPPPPPPPP

Score: 100

User: Cmoss9

Problemset: Consecutive Subsequence

Language: cpp

Time: 0.002 second

Submitted On: 2025-03-22 15:07:15

#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<int> number;
    string a;
    
    while (cin >> a) {
        if (!isdigit(a[0]) && a[0] != '-') break;
        number.push_back(stoi(a));
    }

    sort(number.begin(), number.end());
    number.erase(unique(number.begin(), number.end()), number.end());

    if (number.empty()) return 0;

    int maxcon = 1, count = 1;
    int idx = 0, jdx = 0, start = 0;

    for (int i = 1; i < number.size(); i++) {
        if (number[i] == number[i - 1] + 1) {
            count++;
        } else {
            if (count > maxcon) {
                maxcon = count;
                idx = start;
                jdx = i - 1;
            }
            count = 1;
            start = i;
        }
    }

    if (count > maxcon) {
        maxcon = count;
        idx = start;
        jdx = number.size() - 1;
    }

    for (int i = idx; i <= jdx; i++) {
        cout << number[i] << ' ';
    }
}