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;
    }
  • 相关阅读:
    函数传参-修改文本
    函数传参-商品计价
    嵌套选项卡自动播放
    仿淘宝自动播放菜单栏
    仿淘宝侧边栏菜单
    图片自动切换
    定时器应用-页面弹出广告
    转:Java面试题集(1-50)
    转:115个Java面试题和答案——终极列表(上)
    毕向东day01笔记--dos-jdk-jre-环境变量等
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4657030.html
Copyright © 2011-2022 走看看