AcWing 1204. 错误票据
原题链接
简单
作者:
冷丁Hacker
,
2020-09-14 17:19:45
,
所有人可见
,
阅读 916
stringstream
#include<bits/stdc++.h>
//#include<sstream>
using namespace std;
const int N=1e4+10;
int a[N];
int cnt=0;
int main()
{
int n;
int num;
cin>>n;
string s;
getline(cin,s);
while(n--){
getline(cin,s);
// stringstream ss;
//ss<<s;
stringstream ss(s);
while(ss>>num){
a[cnt++]=num;
}
}
sort(a,a+cnt);
int res1,res2;
for(int i=1;i<cnt;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;
}
方法二 遇到’\n’ break
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int minn=2e9, maxx=-2e9;
int main()
{
int n;
cin >> n;
int x;
while (n--) {
char c;
while (1) {
cin >> x;
char c = getchar();
a[x]++;
minn = min(minn,x);
maxx = max(maxx, x);
if (c == '\n')
break;
}
}
int num1, num2=0;
for (int i = minn; i <= maxx; i++) {
if (a[i] == 0)
num1 = i;
if (a[i] > 1)
num2 = i;
}
cout << num1 <<' '<< num2 << endl;
return 0;
}