首页 > 其他 > 详细

sicily 1200欢迎提出优化方案

时间:2014-04-14 11:19:03      阅读:599      评论:0      收藏:0      [点我收藏+]

水题来的……我的做法是用a[10]数组表示每个数字出现的次数。

1200. Stick

限制条件

时间限制: 1 秒, 内存限制: 32 兆

题目描述

 

 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. 

 

输入格式

 

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. 

 

输出格式

 

For each case, output an integer in a line, which is the length of the last stick. 

 

样例输入

3
1
2
1
0

样例输出

2

题目来源

ZSUACM Team Member

bubuko.com,布布扣
 1 #include<iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 int main()
 5 {
 6    int n,a[101];
 7    while(cin>>n && n){
 8      for(int i=0;i<n;i++) cin>>a[i];
 9      for(int i=0;i<n-1;i++) if(a[i]){
10           for(int j=i+1;j<n;j++)
11                         if(a[i]==a[j]){
12                               a[i]=0;a[j]=0;break;
13                             }
14            continue;
15             }
16       for(int i=0;i<n;i++) if(a[i]) cout<<a[i]<<endl;
17      }
18     return 0;
19 }
View Code

 

sicily 1200欢迎提出优化方案,布布扣,bubuko.com

sicily 1200欢迎提出优化方案

原文:http://www.cnblogs.com/yjf-sicily/p/3662846.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!