AcWing 1204. 错误票据
原题链接
简单
作者:
S_14
,
2022-02-28 20:37:18
,
所有人可见
,
阅读 154
方法一(读法不同)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
using namespace std;
const int N=1e5+10;
int a[N];
int main(){
int x;
cin>>x;
int k=0;
// 第一种读法
for(int i=0;i<x;i++){
int y;
while(cin>>y){
a[k++]=y;
}
}
// 对读入的数据进行处理
sort(a,a+k);
int res1=0,res2=0;// 分别表示 断号和重号;
for(int j=1;j<k;j++){
if(a[j] == a[j-1]){res2=a[j];}
if(a[j] - a[j-1]>=2){res1=a[j]-1;}
}
cout<<res1<<" "<<res2;
return 0;
}
方法二:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
using namespace std;
const int N=1e5+10;
int a[N];
int main(){
int x;
cin>>x;
//第二种读法---标准
string line;
int m=0;
getline(cin,line); // 将回车读入
for(int i=0;i<x;i++){
getline(cin,line);
stringstream ssgn(line);
while(ssgn >> a[m]) m++;
}
// 对读入的数据进行处理
sort(a,a+m);
int res1=0,res2=0;// 分别表示 断号和重号;
for(int j=1;j<m;j++){
if(a[j] == a[j-1]){res2=a[j];}
if(a[j] - a[j-1]>=2){res1=a[j]-1;}
}
cout<<res1<<" "<<res2;
return 0;
}
棒!