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;
    }
  • 相关阅读:
    Python判断操作系统类型
    Linux之计划任务
    java web 之 WebRoot和WebContent目录
    天坑 之 java web servlet+jsp项目 配置后 404 (MyEclipse转eclipse)
    MyEclipse开发的java web项目在 Eclipse中无法识别
    Tomcat 改BUG之 localhost:8080 404
    (重要) html概念之 input:name与id详解
    html基础之 input:type
    BeanUtils 以及BeanUtils.populate使用
    bootstrap 之 列表组件使用
  • 原文地址:https://www.cnblogs.com/yilihua/p/4654758.html
Copyright © 2011-2022 走看看