大家一起做训练 第一场 A Next Test

题目来源:CodeForce #27 A

题目的意思简而言之就是要你输出一个没有出现过的最小的正整数。

  题意如此简单明了,做法也很明了。

  直接读入所有的数,然后排个序,设置个变量从1开始,出现过+1,没出现过输出并break

   1: #include <stdio.h>
   2: #include <iostream>
   3: #include <math.h>
   4: #include <stdlib.h>
   5: #include <string.h>
   6: #include <algorithm>
   7: #include <string>
   8: #include <vector>
   9:  
  10: using namespace std;
  11:  
  12: int main()
  13: {
  14:     int n, res;
  15:     int tmp[3009];
  16:     while (~scanf("%d", &n))
  17:     {
  18:         bool flag = 1;
  19:         for (int i = 0; i < n; i++)
  20:             scanf("%d", &tmp[i]);
  21:         //cout << " !!" << endl;
  22:         sort(tmp, tmp+n);
  23:         res = 1;
  24:         for (int i = 0; i < n; i++)
  25:         {
  26:             if (tmp[i] == res)
  27:                 res++;
  28:             else
  29:             {
  30:                 printf("%d\n", res);
  31:                 flag = 0;
  32:                 break;
  33:             }
  34:         }
  35:         if (flag)
  36:             printf("%d\n", res);
  37:     }
  38:     return 0;
  39: }
posted @ 2013-10-30 20:17  ~無痕~  阅读(330)  评论(0编辑  收藏  举报