zoukankan      html  css  js  c++  java
  • ACM比赛(第二次A)

    ime 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. ($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

    程序分析:此题如果不理解意思可能会觉得比较难,但是如果理解了可能就觉得还好。他的意思就是先输入案例数,在输入下一个数组的元素个数,最后输入数组。然后输出这个数组没有出现的最小两个数。

    解题思路:先把用 memset(x,0,sizeof(x))将数组X清0,然后每次输入一个数就用 x[temp]++这条语句令它为1,最后在从1开始判断这个数是否出现过,如果没出现就输出。然后C++,如果C=2时结束。if(c==1)cout<<" "这条语句很好的处理了输出完第一个数空格,输出完第二个数就结束。如果直接用cout<<i<<" ";就会出现每输出完一个数就有一个空格导致编译通不过。

    #include<iostream>
    #include<cstring>
    using namespace std;
    int x[10006];
    int main(){
        int t;cin>>t;
        while(t--){
            memset(x,0,sizeof(x));
            int t1,temp;cin>>t1;
            for(int i=0;i<t1;i++){
                cin>>temp;
                x[temp]++;
            }
            int c=0;
            for(int i=1;c<2;i++){
                if(x[i]==0){
                    c++;
                    cout<<i;
                    if(c==1)cout<<" ";
                }
            }
            cout<<endl;
        }
    return 0;
    }
  • 相关阅读:
    去哪网 2014.9.25 笔试题
    关于 Private strand flush not complete
    以太网数据帧相关
    Java根据年份算出所属的生肖。
    DWR常用<init-param>参数
    更新ORACLE数据时遇到锁死情况的处理
    Debug of bash , perl and python
    2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)
    I.MX6 wm8962 0-001a: DC servo timed out
    I.MX6 U-boot PWM hacking
  • 原文地址:https://www.cnblogs.com/yilihua/p/4654758.html
Copyright © 2011-2022 走看看