题目来源:CodeForce #27 A
题目的意思简而言之就是要你输出一个没有出现过的最小的正整数。
题意如此简单明了,做法也很明了。
直接读入所有的数,然后排个序,设置个变量从1开始,出现过+1,没出现过输出并break
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <vector>
9:
namespace std;
11:
int main()
13: {
int n, res;
int tmp[3009];
, &n))
17: {
bool flag = 1;
int i = 0; i < n; i++)
, &tmp[i]);
22: sort(tmp, tmp+n);
23: res = 1;
int i = 0; i < n; i++)
25: {
if (tmp[i] == res)
27: res++;
else
29: {
, res);
31: flag = 0;
break;
33: }
34: }
if (flag)
, res);
37: }
return 0;
39: }