zoukankan      html  css  js  c++  java
  • Another test

    Problem 1001 Duplicate Pair

    Accept: 5142    Submit: 24343
    Time Limit: 1000 mSec    Memory Limit : 65536 KB

    Problem Description

    An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.

    Input

    Input contains several cases.
    Each case includes a number n (1<n<=10^6), which is followed by n integers.
    The input is ended up with the end of file.

    Output

    Your must output the value for each case, one per line.

    Sample Input

    2 1 1 4 1 2 3 2

    Sample Output

    1 2

    Source

    IBM Challenge 2004.1 
     1 #include <cstdio>
     2 #include <cstring>
     3 int a[1000005];
     4 int main()
     5 {
     6     int n;
     7     while(scanf("%d",&n) != EOF)
     8     {
     9 
    10         memset(a,0,sizeof a);
    11         int ans = 0;
    12         for(int i = 0 ; i < n ; i++)
    13         {
    14             int temp;
    15             scanf("%d",&temp);
    16             a[temp]++;
    17             if(a[temp] == 2) ans = temp;
    18         }
    19         printf("%d
    ",ans);
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    第一章 初识shiro
    LDAP概念
    css定位
    css随笔1
    自己动手实现信息检索系统
    IntelliJ IDEA和pycharm注册码
    俄罗斯农夫算法
    [NOIP2013]转圈游戏
    [codevs1287]矩阵乘法
    [洛谷1314]无序字母对
  • 原文地址:https://www.cnblogs.com/hyq123456/p/5402970.html
Copyright © 2011-2022 走看看