木棒
来源:互联网 发布:人事调配网络 编辑:程序博客网 时间:2024/05/02 01:10
Problem 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
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
/*map容器是映射容器,提供一对一的映射*/#include<iostream>#include<map>using namespace std;int main(){//freopen("b.txt","r",stdin);int n,x;while(scanf("%d",&n)==1&&n){map<int,int>mp;//map容器的声明,map<int,int>::iterator it;//map容器迭代器的声明while(n--){scanf("%d",&x);mp[x]++;}//while循环完后,mp[1]=2,mp[2]=1;for(it=mp.begin();it!=mp.end();it++)//用迭代器对mp的所以元素遍历{if(it->second%2==1)//如果某元素对应的值为级数,如在此题中,mp[2]=1{printf("%d\n",it->first);//输出该元素,在此题中输出2break;}}}return 0;}
0 0
- 木棒
- 木棒
- 木棒
- 木棒
- 木棒问题
- 木棒三角形
- poj_1011木棒
- poj1011木棒
- poj 木棒
- 木棒三角形
- 【poj1011】木棒
- POJ1011 木棒
- POJ1011 木棒
- 凑木棒
- POJ1011 木棒
- 木棒拼图
- 木棒问题
- 木棒问题
- “模”法无边-设计模式6
- malloc函数和new
- vfprintf、vprintf和vsprintf函数
- 循环-14. 最大公约数和最小公倍数(15)
- POJ 1274The Perfect Stall(二分图最大匹配)
- 木棒
- 赫夫曼编码
- 池稼蒂痉蕉推禄股洗扛四只犹梁少
- MySql基本语法(学习笔记)
- HDU1701 ACMer 【浮点数误差】
- C# 格式化format 常见命令
- Mysql存储过程(六)——存储过程中使用临时表
- windows7 下安装 redhat 双系统 easybcd
- Android应用开发--动画详解