sicily Stick
来源:互联网 发布:网络拓扑图算法 编辑:程序博客网 时间:2024/06/05 00:12
题目
Description
Anthony has collected a large amount of sticks for manufacturing chopsticks. In order to simplify his job, he wants to fetch two equal-length sticks for machining at a time. After checking it over, Anthony finds that it is always possible that only one stick is left at last, because of the odd number of sticks and some other unknown reasons. For example, Anthony may have three sticks with length 1, 2, and 1 respectively. He fetches the first and the third for machining, and leaves the second one at last. You task is to report the length of the last stick.
Input
The input file will consist of several cases.
Each case will be presented by an integer n (1<=n<=100, and n is odd) at first. Following that, n positive integers will be given, one in a line. These numbers indicate the length of the sticks collected by Anthony.
The input is ended by n=0.
Output
For each case, output an integer in a line, which is the length of the last stick.
Sample Input
31210
Sample Output
2
解题思路
简单得我都觉得不会有人来看这个了,虽然代码中直接用了set,但其实开一个bool数组应该会占用更少空间,更快
代码
#include <iostream>#include <set>#include <iterator>using namespace std;int main(int argc, const char * argv[]) { int n; set<int> stick_lengths; set<int>::iterator iter; while (1) { cin >> n; if (n == 0) break; int t_length; while (n--) { cin >> t_length; iter = stick_lengths.find(t_length); if (iter == stick_lengths.end()) { stick_lengths.insert(t_length); } else { stick_lengths.erase(iter); } } cout << *stick_lengths.begin() << endl; stick_lengths.clear(); } return 0;}
- sicily stick
- sicily Stick
- Sicily 1200. Stick
- sicily--1200. Stick
- sicily 1200stick
- Sicily 1200 stick
- Sicily 1200. Stick
- Sicily 1200 stick
- Sicily 1200. Stick
- [sicily]1200. Stick
- sicily 1200. Stick
- Stick
- Stick
- Stick
- stick
- stick
- stick
- stick
- 区间更新线段树
- 数据结构之图
- HTML5+CSS3+JS学习笔记-7-JS调节背景色
- WX-逻辑层
- 161222
- sicily Stick
- TopM实现
- 常用的简单html标签
- 【易语言界面开发系列教程之(EX_UI使用系列教程(13)--设置鼠标指针皮肤)】
- ViewPager+Fragment延迟加载
- 父进程与子进程
- Servlet
- 也咬文嚼字
- 关于windows下在while中先输入回车再输入ctrl+Z()才能表示EOF的解答