好的,我需要找出一个数组中有多少个不同的数字。
例如,如果数组是:1 9 4 5 8 3 1 3 5
输出应该是6,因为1、9、4、5、8、3是唯一的,而1、3、5是重复的(不唯一)。
以下是我目前的代码..... 不起作用。
#include <iostream>
using namespace std;
int main() {
int r = 0, a[50], n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int j = 0; j < n; j++) {
for (int k = 0; k < j; k++) {
if (a[k] != a[j]) r++;
}
}
cout << r << endl;
return 0;
}