Stick
2015-09-26 11:24
543 查看
1200. Stick
Constraints
Time Limit: 1 secs, Memory Limit: 32 MBDescription
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 alwayspossible 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
// stick.cpp
#include <iostream>
#include <set>
using namespace std ;
int main (){
int flag = 0 ; cin >> flag ;
while(flag != 0){
set<int> stickes ;
int first ; cin >> first ; stickes.insert(first) ;
while(flag -- > 1 ){
int x ; cin >> x ;
if( stickes.count(x) ){
stickes.erase(x) ;
}
else{
stickes.insert(x) ;
}
}
set<int>::iterator iter ;
for ( iter = stickes.begin() ; iter != stickes.end() ; ++iter )
{
cout << *iter << endl ;
}
cin >> flag ;
}
}
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- PostgreSQL新手入门教程
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- 解析C++中派生的概念以及派生类成员的访问属性