【样例输入】
1 2 4?
【样例输出】
缺失的数字是:3
?
#include<iostream>
using namespace std;
int find(int arr[], int n)
{
int missing=0;
for (int m = 0; m < n; m++) {
if (arr[m] !=m+1 ) {
missing = m+1;
break;
}
}
return missing;
}
int main()
{
int arr[100] = { 0 };
int n, i = 0;
do {
scanf("%d", &n);
arr[i++] = n;
} while (getchar() != '\n');
int missing = find(arr, i);
if (missing != 0) {
cout << "缺失的数字是:" << missing << endl;
}
return 0;
}
?