zoukankan      html  css  js  c++  java
  • 2015 HUAS Provincial Select Contest #2 A

    题目:

    Description

    There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.
     

    Input

    There is a number  shows there are  test cases below. (
    For each test case , the first line contains a integers  , which means the number of numbers the permutation has. In following a line , there are  distinct postive integers.()
     

    Output

    For each case output two numbers , small number first.
     

    题目大意:输入N连续个数,求它的最小的两个数。

    解题思路:用一个数组存储这N个数,再用另个数组存储1—N+2的连续数,再两个数组比较,输出缺了的两项。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #define maxn 1010
     4 using namespace std;
     5 int main()
     6 {
     7     int T;
     8     cin >> T;
     9     if(T<=10)
    10     {
    11         while (T--)
    12         {
    13             int n, a[maxn],b[maxn] ,i,d;
    14             cin >> n;
    15             if(n>=1&&n<=1000)
    16             {
    17                 d=0;
    18                 for (i = 0; i <n; i++)
    19                     cin >> a[i];
    20                 for(i=0;i<n+2;i++)
    21                     b[i]=i+1;
    22                 
    23                 for(i=0;i<n;i++)
    24                 {
    25                     for(int j=0;j<n+2;j++)
    26                     {
    27                         if(a[i]==b[j])
    28                             b[j]=0;
    29                     }
    30                 }
    31                 for(i=0;i<n+2;i++)
    32                 {
    33                     if(b[i]!=0)
    34                     {    
    35                         d++;
    36                         if(d==2)
    37                             printf("%d
    ",b[i]);
    38                         else printf("%d ",b[i]);
    39                         
    40                     }
    41                 }
    42             }        
    43         }
    44     }    
    45     return 0;    
    46 }
  • 相关阅读:
    web app变革之rem
    理解angularjs的作用域
    移动开发框架
    angularjs ng-repeat下验证问题
    10、长链接转短链接
    8、自定义菜单及菜单响应事件的处理
    9、多公众号集中管理
    7、消息管理-接收事件推送
    6、消息管理-普通消息接受处理
    5、用户和用户组管理-支持同步
  • 原文地址:https://www.cnblogs.com/huaxiangdehenji/p/4652339.html
Copyright © 2011-2022 走看看