顺序表删除 SDTU1130
简单题
开个数组一下过了,貌似觉得不合符题目要求,题目要求是尽可能小的空间和时间,想不到有啥好方法
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1
2
3 1 #include<iostream>
4 2 using namespace std;
5 3
6 4 bool notfind(int, int[], int);
7 5 int main()
8 6 {
9 7 int num;
10 8 int n = 0;
11 9 int i = 0;
12 10 int a[1000], b[1000];
13 11
14 12 cin >> num;
15 13
16 14 while(cin >> a[i++]);
17
18 16 for (int j = 0; j < num; j++)
19 17 {
20 18 if (notfind(a[j], b, n))
21 19 {
22 20 b[n++] = a[j];
23 21 }
24 22 }
25 23
26 24 cout << n << endl;
27 25 for (int i = 0; i < n - 1; i++)
28 26 cout << b[i] << " ";
29 27 cout << b[n-1] << endl;
30 28
31 29 return 0;
32 30 }
33 31
34 32 bool notfind(int a, int b[], int num)
35 33 {
36 34 for (int i = 0; i < num; i++)
37 35 {
38 36 if (a == b[i])
39 37 return false;
40 38 }
41 39 return true;
42 40 }
43 41
44 42