使用set容器, 因为set中保存的元素值是唯一的,故将输入值插入的set容器中,最后求大小即可:
#include
using namespace std;
int main()
{
int n, x;
set st;
cin >> n;
for(int i = 0; i < n; i++)
cin >> x;
st.insert(x);
}
cout << st.size() << endl;
测试如下: