• AcWing 1204. 错误票据


    题目:
    某涉密单位下发了某种票据,并要在年终全部收回。

    每张票据有唯一的ID号。

    全年所有票据的ID号是连续的,但ID的开始数码是随机选定的。

    因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成了某个ID断号,另外一个ID重号。

    你的任务是通过编程,找出断号的ID和重号的ID。

    假设断号不可能发生在最大和最小号。

    输入格式
    第一行包含整数 N,表示后面共有 N 行数据。

    接下来 N 行,每行包含空格分开的若干个(不大于100个)正整数(不大于100000),每个整数代表一个ID号。

    输出格式
    要求程序输出1行,含两个整数 m,n,用空格分隔。

    其中,m表示断号ID,n表示重号ID。

    数据范围

    [1≤N≤100 ]

    输入样例:

    2
    5  6  8  11  9
    10  12  9
    

    输出样例:

    7 9
    

    代码:

    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    const int N = 10010;
    
    int n;
    int a[N];
    int main()
    {
    	int cnt;
    	cin >> cnt;
    	string line;
    	
    	getline(cin, line);	// 忽略第一行的回车 
    	while(cnt --)
    	{
    		getline(cin, line);
    		stringstream ssin(line);
    		
    		while(ssin >> a[n]) n ++;
    	}
    	
    	sort(a, a + n);
    	int res1 = 0, res2 = 0;
    	for(int i = 1; i < n; i ++)
    		if(a[i] == a[i - 1]) res2 = a[i];	//重号 
    		else if(a[i] >= a[i - 1] + 2) res1 = a[i] - 1;	// 断号 
    	
    	cout << res1 << " " <<  res2 << endl;
    	return 0;
    } 
    
  • 相关阅读:
    Python基础检测:20171105
    Python中斐波那契数列的四种写法
    Python中斐波那契数列的四种写法
    学习Python3:20171031
    学习Python3:20171031
    9.3 Trains and Evaluates the MNIST network using a feed dictionary
    9.3 Trains and Evaluates the MNIST network using a feed dictionary
    学习Python3:201701030
    学习Python3:201701030
    周末微光
  • 原文地址:https://www.cnblogs.com/xiaofrank/p/14358729.html
Copyright © 2020-2023  润新知