1. Problem description
11
10
20
40
32
67
40
20
89
300
400
15
10
15
20//只显示1次
32
40//只显示1次
67
89
300
400
Normal algorithm:
1. Traverse all the arrays and remove duplicate numbers
2. Use the XX sorting method to sort the numbers.
Eye-catching machine algorithms
1. Generate an array of 1-1000 and give all 0
2. Input, or generate random numbers, set the array value corresponding to the random number to 1
and enter the number 15, then a[15] = 1;
3. Traverse all the arrays , if a[i]>0, output i.
#include<iostream>
using namespace std;
int main()
{
int i, k, N, L;
int a, Hash[1001];
while (cin >> N)
{
/*初始化1000个数组*/
for (i = 0; i<1001; i++)
Hash[i] = 0;
/*输入排列的数组,将这个数字的地方置1*/
for (i = 0; i<N; i++)
{
cin >> a;
Hash[a]++;
}
/*遍历1000个数组 如果这个地方是大于1就打印*/
for (i = 0; i<1001; i++)
if (Hash[i]>0)
cout << i << endl;
}
return(0);
}
expand
int main()
{
int arr[100], sum = 0;
char c;
int x = 4;
while (x--)
{
cin >> c;
arr[c] = 1;
}
for (int i = 0; i < 100; i++)
if (arr[i] == 1)
sum++;
cout << sum;
system("pause");
}