zoukankan      html  css  js  c++  java
  • HDU 5166(缺失数查找输出)

    HDU 5166

    Time Limit:1000MS  Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    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. (0<=T <=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 <=n <=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

     题解:找出一个数列中缺的两个数(这两个数要为最小的两个数)。

      注意:利用bool函数把数组中所有数全部返回0

     

    #include<stdio.h>
      int main()
      {
          int T,i;
         scanf("%d",&T);
         while(T--)
          {
              int count,t=0,j[2];;
              scanf("%d",&count);
             bool flag[1005]={  false  };
            for( i=1;i<=count;i++)
             {
                 int tem;
                 scanf("%d",&tem);
                 flag[tem]=true;//每输入一个数s,便给第s个赋值为1
             }
             
             
             for(i=1;i<=count+2;i++)
             {
                 if(flag[i]==0)//如果有为0的出现,则为缺失的数
                 {
                     j[t++]=i;    
                 }
            }
             printf("%d %d
    ",j[0],j[1]);
             
         }
         return 0;
     }

    多多交流~ 

  • 相关阅读:
    centos5.8下用shell脚本监控服务器
    linux下IPTABLES配置详解
    centos设置计划任务(cron)
    32位CentOS系统安装kernel-PAE支持4g以上内存
    Excel同时打开多个独立的窗口
    yum安装LAMP
    多字段指定不同方向排序
    MySQL基础
    Python 网络编程
    Python 并发编程
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4654733.html
Copyright © 2011-2022 走看看