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;
    }
  • 相关阅读:
    Springboot+resteasy定时任务
    MySql COUNT(),SUM()组合用法
    MySql按每日、每周、每月分组统计数据
    阿里云通过访问地址来缩小图片,减少流量消耗
    ExtJs6获取form里的数据
    postfix中recipient/client/sender/helo四者的区别<转载>
    用telnet命令,POP3接收邮件
    用telnet命令,SMTP发送邮件
    Linux 标准目录结构
    centos minimal Bind 主从服务器部署
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4657030.html
Copyright © 2011-2022 走看看