Blue Bridge Cup - Error Bill

Topic description: A
secret-related unit has issued a certain kind of bill, and it will all be recovered at the end of the year.
Each ticket has a unique ID number. The ID numbers for all notes throughout the year are consecutive, but the starting numbers of the IDs are randomly selected. Due to the negligence of the staff, an error occurred when entering the ID number, resulting in a broken ID for one ID and a duplicate ID for another ID. Your task is to programmatically find out the ID of the break number and the ID of the double number.
It is assumed that break numbers cannot occur at the largest and smallest numbers.
The program is required to first input an integer N (N<100) to represent the number of data lines that follow.
Then read in N lines of data.
The length of each line of data varies, and is a number of (not more than 100) positive integers (not more than 100,000) separated by spaces.
Each integer represents an ID number.
The program is required to output 1 line, containing two integers mn, separated by spaces.
Among them, m represents the break ID, and n represents the repeated ID
input:
the program is required to first input an integer N (N<100) to represent the number of subsequent data lines.
Then read in N lines of data.
The length of each line of data varies, and is a number of (not more than 100) positive integers (not more than 100000) separated by spaces. Each integer represents an ID number.

Output:
The program is required to output 1 line, containing two integers mn, separated by spaces.
Among them, m represents the break ID, n represents the repeat ID

Sample Input
2
5 6 8 11 9
10 12 9
Sample Output
7 9
Submit Code

#include <iostream>
#include<cstdio>
#include <set>
using namespace std;
typedef long long ll;
int main()
{
    set<ll>s;
    ll row,size,n = 0,m  = 0;
    cin >> row;
    ll a;char op;
    while(row)
    {
        scanf("%lld%c",&a,&op);//这里解决了换行问题
        size = s.size();
        s.insert(a);
        if(size == s.size())//在这里,只要s的长度不变,说明这是个重复元素
            n = a;
        if(op == '\n')row--;
    }
    set<ll>::iterator it = s.begin();
    set<ll>::iterator iter = it;
    for(it++; it != s.end();it++,iter++)
    //在这里,如果一个元素的下一个元素不等于该元素加一,则说明此处有缺失
        if(*it != *iter + 1)
            m = *iter + 1;

    cout << m << " " << n;
    return 0;
}

All right! In fact, for this question, the test data I entered is no problem, but I can't get AC on the oj of a certain college. If you find any problems, be sure to tell me!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325862104&siteId=291194637