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 (T) shows there are (T) test cases below. ($T leq 10$) 
    For each test case , the first line contains a integers (n) , which means the number of numbers the permutation has. In following a line , there are $n$ distinct postive integers.($1 leq n leq 1,000$)
     

    Output

    For each case output two numbers , small number first.
     

    Sample Input

    2 3 3 4 5 1 1
     

    Sample Output

    1 2 2 3
    解题思路:这个题要注意的是长度为n的排列就是从1~n这连续的n个数,而不是任意数;其次,大数组一般是定义在函数外,或者动态申请的,不会在栈中。因为桟的内存比较小,没有主函数外大,定义在内部容易造成系统栈过载的这种错误。
    程序代码:
    #include<cstdio>
    const int maxn=1000;
    int a[1000],b[1000];
    int main()
    {
     int T;
     scanf("%d",&T);
     while(T>=1&&T<=10)
     {
     
      while(T--)
      {
       int i,n,k;
             scanf("%d",&n);
       if(n>=1&&n<=1000)
       {
        k=0; 
        for(i=0;i<n;i++)
                     scanf("%d",&a[i]);
                 for(i=0;i<n+2;i++)
         b[i]=i+1;
        for(i=0;i<n;i++)
        {
         for(int j=0;j<n+2;j++)
         {
          if(a[i]==b[j])
          b[j]=0;
         }
        }
       
        for(i=0;i<n+2;i++)
        {
         if(b[i]!=0) 
         {
          k++;
          printf("%d",b[i]);
          if(k==2)  printf(" ");
          else printf(" ");
         }
        }
       }
      }
     }
     return 0;
    }
  • 相关阅读:
    c++字符串排序
    JAVA实现四则运算的简单计算器
    JAVA图形小动画之简单行星运动
    JAVA多线程编程
    ege图形库之简单贪吃蛇(c++)
    ege图形库之动画排序
    mysql 性能优化方案
    MYSQL 优化常用方法
    [手把手教你] 用Swoft 搭建微服务(TCP RPC)
    php有效防止同一用户多次登录
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4657030.html
Copyright © 2011-2022 走看看