ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

错误票据题解

错误票据题解

1、错误票据

题目信息

在这里插入图片描述

思路

先对数组进行排序,然后遍历数组,如果出现两个一样的,就是重号,如果连续的两个数之间相差大于1就是断号

题解

#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;const int maxn=1000005;
int a[maxn]={0};
int n,pos=0;
int main(){hh;cin>>n;while(n--){while(cin>>a[pos]){pos++;if(cin.get()=='\n'){break;}}}int ansB=a[0],ansR=a[0];sort(a,a+pos);for(int i=0;i<pos;i++){if(a[i]!=a[i-1]+1&&a[i]!=a[i-1]){ansB=a[i]-1;}if(a[i]==a[i-1]){ansR=a[i];}}cout<<ansB<<' '<<ansR<<endl;return 0;
}
返回列表