solution.cpp 770 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
//代码3
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int ans[10005];
char str[100001];
int main()
{
    int n;
    cin >> n;
    int i, k = 0;
    getchar();
    for (i = 0; i < n; i++)
    {
        gets(str);
        char *p;
        p = strtok(str, " ");
        ans[k++] = atoi(p);
        while (p)
        {
            p = strtok(NULL, " ");
            if (p)
                ans[k++] = atoi(p);
        }
    }
    sort(ans, ans + k);
    int ans1, ans2;
    for (i = 0; i < k - 1; i++)
    {
        if (ans[i + 1] - ans[i] == 2)
        {
            ans1 = ans[i] + 1;
        }
        if (ans[i + 1] == ans[i])
            ans2 = ans[i];
    }
    cout << ans1 << " " << ans2;
}