码迷,mamicode.com
首页 > 其他好文 > 详细

Sicily-Stick

时间:2017-01-19 18:05:33      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:++   spec   desc   unknown   imp   leaves   ber   port   order   

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

3
1
2
1
0

 

Sample Output

2

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<string>
 4 #include<cstring>
 5 using namespace std;
 6 int main() {
 7     int m;
 8     while(cin >> m && m != 0) {
 9         int a[100] = {0};
10         for (int i = 0; i < m; i++) {
11             cin >> a[i];
12         }
13         sort(a, a+m);
14         int count = 0;
15         for (int i = 0; i < m - 1; i+=2) {
16             if (a[i]!=a[i+1]) {
17                 cout << a[i] << endl;
18                 count = 1;
19                 break;
20             }
21         }
22         if (count == 0) {
23             cout << a[m-1] << endl;
24         }
25     }
26 }

 

 

Sicily-Stick

标签:++   spec   desc   unknown   imp   leaves   ber   port   order   

原文地址:http://www.cnblogs.com/SYSU-Bango/p/6307237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!