Sicily-Stick
Posted SYSU_Bango
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sicily-Stick相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章