Blue Bridge Cup algorithm solution to a problem the previous questions wrong notes

Title Description

Problem Description
made some notes of a secret unit down, and to be fully recovered at the end of the year.
Each ticket has a unique ID number. All annual bill ID number is continuous, but the beginning of a digital ID is randomly selected.
Because of staff negligence, an error occurred when entering the ID number, resulting in a broken ID number, the other a heavy ID number.
Your task is programmed to find the ID ID number and weight of broken numbers.
Suppose off number unlikely to occur in the minimum and maximum number.

Input format
required first enter a program integer N (N <100) represents the number of rows of data that follows.
Then reads the data of N lines.
Each row of unequal length, with a plurality of separated spaces (less than 100) positive integer (not more than 100,000), please note that the line may have extra spaces and end of the line, you need to be able to handle the program space.
Each integer representing an ID number.

Output format
required program output line 1, containing two integers Mn, separated by spaces.
Wherein, m represents the number of broken ID, n represents the ID number of weight

Sample Input 1
2
. 5. 6. 8. 11. 9
10. 9 12 is
a sample output 1
. 7. 9

Sample input 2
. 6
164 is 178 108 109 182 180,155,141,159,104 179,118,137,184,115 124,125,129,168,196
172,189,127,107,112 192,103,131,133,169 158
128 102 110 148 139,157,140,195,197
185,152,135,106,123 173,122,136,174,191 145,116,151,143,175 120,161,134,162,190
149,138,142,146,199 126,165,156,153,193 144,166,170,121,171 132,101,194,187,188
113,130,176,154,177 120,117,150,114,183 186,181,100,163,160 167,147,198,111,119
sample output 2
105 120

answer:

This question is very simple, a row order, which determines the number of weight is equal to the previous number of number n, the number of which - in front of a number of off = 2 indicates that the intermediate number is m.

Code :

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;

typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll  INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int MOD = 1e9+7;
const int MAX = 1e5+5;

int N;
vector <int> vec;
int m,n;

int main()
{
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */
    cin >> N;
    int num;
    while(scanf("%d",&num) != EOF)
    {
        vec.push_back(num);
    }
    sort(vec.begin(),vec.end());
    for(int i = 1; i < (int)vec.size(); i++)
    {
        if(vec[i]-vec[i-1] == 2)
        {
            m = vec[i]-1;
        }
        if(vec[i] == vec[i-1])
        {
            n = vec[i];
        }
    }
    cout << m << " " << n << endl;

    return 0;
}
He published 197 original articles · won praise 18 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_41708792/article/details/105332123