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 }
时间: 2024-10-12 23:40:31

Sicily 2005.Lovely Number的相关文章

sicily 2010 H number

解释:根据规则构造数字,而不是从头遍历一遍判断,这样可以避免很多不必要的计算. 运行效率:0秒,312KB. 代码如下,类似广度优先搜索: #include<stdio.h> #include<string.h> #include <iostream> #include<queue> using namespace std; //int toInt(char c){ return c-'0'; } //char toChar(int i){ return i

Duff in Love_数论_素因子应用

Duff in Love TimeLimit:2000MS  MemoryLimit:256MB 64-bit integer IO format:%I64d Problem Description Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a di

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

Sicily 1732 Alice and Bob (二进制数的最大公约数)

链接: http://soj.me/1732 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description: Alice is a beautiful and clever girl. Bob would like to play with Alice. One day, Alice got a very big rectangle and wanted to divide it into small square pieces.

URAL 2005. Taxi for Programmers (最短路 数学啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2005 2005. Taxi for Programmers Time limit: 0.5 second Memory limit: 64 MB The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have just finished their trai

sicily 1240. Faulty Odometer

Description You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 3 to the digit 5, always skipping over the digit 4. This defect shows up in all positions (the on

Timus 2005. Taxi for Programmers 题解

The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have just finished their training. The exhausted students gloomily leave their computers. But there's something that cheers them up: Misha, the kind coach

[转]Under the covers: IAM chains and allocation units in SQL Server 2005

(I'm sitting here in Seattle airport at 7am on Sunday waiting to catch the same flight to Boston that I caught two weeks ago. Instead of TechEd, this time I'm going to a training course at MIT. I'd enjoy the air travel a lot more with a bigger gap in

如何使用 Visual C# 2005 或 Visual C# .NET 向 Excel 工作簿传输数据

本文分步介绍了多种从 Microsoft Visual C# 2005 或 Microsoft Visual C# .NET 程序向 Microsoft Excel 2002 传输数据的方法.本文还提供了每种方法的优点和缺点,以便您可以选择最适合您的情况的解决方案. 概述 最常用于向 Excel 工作簿传输数据的方法是"自动化".利用"自动化"功能,您可以调用特定于 Excel 任务的方法和属性."自动化"功能为您提供了指定数据在工作簿中所处的位