codeforces 992A

Nastya and an Array
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
题意 :
给你n个数,让你求这个数列中有多少个不同的数(0)除外;
题解
显然很简单,我们可以利用set容器的驱重的性质直接解决这个问题,遇到不是0的数直接存入set
代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
  set<int>se;
  int n;int x;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      cin>>x;
      if(x==0)continue;
      se.insert(x);
  }
  cout<<se.size()<<endl;
}

猜你喜欢

转载自blog.csdn.net/qq_40623603/article/details/86588977