食油大学 acm14641: Distinct or Not

Given is a sequence of integers A1,A2,…,AN. If its elements are pairwise distinct, print YES; otherwise, print NO.

Constraints
·2≤N≤200000
·1≤Ai≤109
·All values in input are integers.

Input is given from Standard Input in the following format:

N
A1 … AN

输出
If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.
样例输入 Copy
【样例1】
5
2 6 1 4 5
【样例2】
6
4 1 3 1 6 2
【样例3】
2
10000000 10000000
样例输出 Copy
【样例1】
YES
【样例2】
NO
【样例3】
NO
提示
样例1解释
The elements are pairwise distinct.
样例2解释
The second and fourth elements are identical.

这个题如果一个一个遍历估计会超时,正好用上刚学的set,自动存储时去重,最后只需要比较个数就好,不多说,贴码

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    set <int> s;
    int a[200020];
    int i,n;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    int cnt=0;
    set<int>::iterator it;
    for(it=s.begin();it!=s.end();it++)
    {
        cnt++;
    }
    if(cnt==n)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值