topic link address
Notice
The code I wrote before does not need ctrl+z to end the input, and the blue bridge evaluation system should be ctrl+z and enter to end the input, so it cannot end, and I keep reporting errors. +z is used to end the input current while input loop, enter means to get characters from the input buffer.
#include<stdio.h> #include <iostream> #include <string> #include <set> #include <string.h> #include <stdlib.h> using namespace std; int main() { int n; while( (cin >> n) ) { cout << n << endl; } return 0; }
In the above code, press enter after each input, the data will be read and output, and the input while loop will be jumped out only when ctrl+z and enter are input.
- URL of other people's code: https://blog.csdn.net/milkcu/article/details/9090515
my code
#include<stdio.h>
#include <iostream>
#include <string>
#include <set>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
int lines;
string str;
cin >> lines;
set<int> result;
int num1 = 0, num2 = 0;
char s[100000];
for (int i = 0; i < lines; i++)
{
memset( s, 0, sizeof(s) );
cin.clear();
cin.sync();
cin.getline(s, 100000);
int index = 0;
int num = 0;
string str(s);
//str.assign( s, s+strlen(s) );
while( index < str.size() && str[index] == ' ' )
index++;
while (index < str.size())
{
int currIdx = str.find(' ', index);
if (currIdx != -1)
num = atoi(str.substr(index, currIdx - index).c_str());
else
num = atoi(str.substr(index).c_str());
if (result.count(num) == 1)
num1 = num;
result.insert(num);
if (currIdx == -1)
break;
index = currIdx + 1;
while (index < str.size() && str[index] == ' ')
index++;
}
}
int start = *(result.begin());
int diff = 0;
for (set<int>::iterator it = result.begin(); it != result.end(); it++)
{
if (*it - start != diff)
{
num2 = diff + start;
break;
}
diff++;
}
cout << num2 << " " << num1 << endl;
return 0;
}
other people's code
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
void print(int x) {
cout << x << " ";
}
int main(void) {
vector<int> v;
getchar();
int tmp;
//while(scanf("%d", &tmp) == 1) {
while(cin >> tmp) {
v.push_back(tmp);
}
sort(v.begin(), v.end());
int m = 0;
int n = 0;
for(vector<int>::iterator iv = v.begin(); iv != v.end(); iv++) {
int tmp = *(iv + 1) - *iv;
if(tmp == 2) {
//duanhao
m = *iv + 1;
}
if(tmp == 0) {
//chonghao
n = *iv;
}
if(m != 0 && n != 0) {
break;
}
}
cout << m << " " << n << endl;
return 0;
}