Sicily 2005.Lovely Number

题目地址:2005.Lovely Number

思路:

  若测试数据出现的次数为奇数,则输出它。

    所以,可以先排序,若前后相等,前后都设为0,最后不为0的则可以输出。

    具体代码如下:

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 int main() {
 6     int t;
 7     while (cin >> t) {
 8         int *array = new int[t]; 
 9         for (int i = 0; i < t; i++) {
10             cin >> array[i];
11         }
12         sort(array, array+t);
13         for (int i = 0; i < t-1; i++) {
14             if (array[i] == array[i+1]) {
15                 array[i] = 0;
16                 array[i+1] = 0;
17                 i++;  //跳过下一次循环 
18             }
19         }
20         for (int i = 0; i < t; i++) {
21             if (array[i] != 0) {
22                 cout << array[i] << endl;
23             }
24         }
25     }
26     
27     return 0;
28 }
原文地址:https://www.cnblogs.com/winray/p/4093934.html