zoukankan      html  css  js  c++  java
  • 大家一起做训练 第一场 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
    ", res);
      31:                 flag = 0;
      32:                 break;
      33:             }
      34:         }
      35:         if (flag)
      36:             printf("%d
    ", res);
      37:     }
      38:     return 0;
      39: }
  • 相关阅读:
    Largest Rectangle in Histogram
    Valid Sudoku
    Set Matrix Zeroes
    Unique Paths
    Binary Tree Level Order Traversal II
    Binary Tree Level Order Traversal
    Path Sum II
    Path Sum
    Validate Binary Search Tree
    新手程序员 e
  • 原文地址:https://www.cnblogs.com/wuhenqs/p/3397671.html
Copyright © 2011-2022 走看看