maninbule / LanQiaoCup

蓝桥杯刷题活动
0 stars 0 forks source link

1204. 错误票据 #28

Open maninbule opened 4 years ago

maninbule commented 4 years ago

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
maninbule commented 4 years ago
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int N,m,n;
map<int,int> mp;
int main(){
    cin>>N;int cur;
    while(scanf("%d",&cur)!=EOF){
        mp[cur]++;
    }
    for(auto M:mp){
        if(!mp.count(M.first+1) && mp.count(M.first+2)) m = M.first+1;
        if(M.second == 2) n = M.first;
    }
    cout<<m<<" "<<n<<endl;

    return 0;
}
patern2000 commented 4 years ago

include

include

define N 10001

using namespace std; char num[6]; int main() { int n; int len=0; int a[N]; cin>>n; while(cin>>a[len++]); sort(a,a+len); for(int i=1; i<len; i++) if(a[i]-a[i-1]==2) { cout<<a[i]-1<<' '; break; } for(int i=1; i<len; i++) if(a[i]-a[i-1]==0) { cout<<a[i]; break; } return 0; }

maobohui commented 4 years ago
#include<bits/stdc++.h>
using namespace std;
int n,tem;
int maxs=0,mins=100001;
string str;
const int maxn = 1e5+10;
int num[maxn];
int main(){
    cin>>n;
    getchar();
    while(n--){
        stringstream s;
        getline(cin,str);
        s<<str;
        while(s>>tem){
            num[tem]++;
            if(tem>maxs){
                maxs=tem;
            }
            if(tem<mins){
                mins=tem;
            }
        }
    }
    int ans=0,res=0;
    for(int i=mins+1;i<=maxs-1;i++){
        if(num[i]==2){
            res=i;
        }
        else if(num[i]==0){
            ans = i;
        }
        if(ans&&res){
            break;
        }
    }
    printf("%d %d\n",ans,res);
    return 0;
}
consult98 commented 4 years ago
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e5+7;
int a[N];
int main()
{
    int n,i=0;
    cin>>n;
    while(scanf("%d",&a[i])!=EOF){
        i++;
    }
    sort(a,a+i);
    int A,B;
    for(int j=1;j<i;j++){
        if(a[j-1]==a[j]-2) A = a[j-1]+1;
        if(a[j-1]==a[j]) B = a[j];
    }
    cout<<A<<" "<<B<<endl;
    return 0;
 } 
LJM-Jeson commented 4 years ago
#include <bits/stdc++.h>

using namespace std;

const int N = 110, M = 100010, INF = 10000000;

//数组vle存入值M出现的次数
int vle[M];

int main(){
    int line, m, n, i;
    int v, minv = INF, maxv = -INF;
    cin >> line;

    while(line --){
        while(cin >> v){
            minv = min(minv, v);//更新最小值
            maxv = max(maxv, v);//更新最大值
            vle[v] ++;
        }
    }

    //断号出现0次即i ==0,重号出现2次即i == 2
    for(int i = minv; i <= maxv; i ++){
        if(vle[i] == 0) m = i;
        if(vle[i] == 2) n = i;
    }

    cout << m << ' ' << n;
    return 0;
}
xunzhang123 commented 4 years ago

include

include

using namespace std;

const int N = 105; int a[N*N]; int main() { int n;cin >> n; int len = 0; while(n--) while(cin >> a[len++]); sort(a,a+len); int resm = 0,resn = 0; for(int i = 0;i < len;++i) { if(a[i] == a[i + 1] - 2) resm = a[i] + 1; if(a[i] == a[i + 1]) resn = a[i]; } cout << resm << " " << resn; return 0; }