您的位置:首页 > 编程语言 > C语言/C++

Stick

2015-09-26 11:24 543 查看

1200. Stick

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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


// 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 ;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sicily c++ 新手