博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ignatius and the Princess IV
阅读量:6864 次
发布时间:2019-06-26

本文共 2144 字,大约阅读时间需要 7 分钟。

Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d & %I64u
 

Description

"OK, you are not too bad, em... But you can never pass the next test." feng5166 says. 
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says. 
"But what is the characteristic of the special integer?" Ignatius asks. 
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says. 
Can you find the special integer for Ignatius? 
 

Input

The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file. 
 

Output

For each test case, you have to output only one line which contains the special number you have found. 
 

Sample Input

5 1 3 2 3 3 11 1 1 1 1 1 5 5 5 5 5 5 7 1 1 1 1 1 1 1
 

Sample Output

 

3 5 1
 
 
1.
1 #include
2 #include
3 4 int main() 5 { 6 int i,j; 7 int N,num; 8 int x,cas; 9 while(scanf("%d",&N)!=EOF)10 {11 num=0;12 for(i=1;i<=N;i++)13 {14 scanf("%d",&cas);15 if(num==0)16 {17 x=cas;18 num++;19 }20 else21 {22 if(x==cas)23 num++;24 else25 num--;26 }27 }28 printf("%d\n",x);29 }30 return 0;31 }
View Code

2.

1 #include
2 #include
3 #include
4 using namespace std; 5 int a[1000005]; 6 int main() 7 { 8 int i,j,N; 9 10 while(scanf("%d",&N)!=EOF)11 {12 for(i=0;i
View Code

 

 
 

转载于:https://www.cnblogs.com/cyd308/p/4492573.html

你可能感兴趣的文章
MyEclipse的文本编辑器
查看>>
菜鸟初长成
查看>>
log4j.properties配置详解
查看>>
8天学通MongoDB——第二天 细说增删查改
查看>>
自律给我自由 2017.8.9 心情很好 天气很好
查看>>
2016年3月23日作业(项目进度管理、项目成本管理)
查看>>
redmine3.3.1安装与常用插件安装
查看>>
Python生成随机五位数——模仿手机验证码
查看>>
华为认证网络互连专家-HCIE-R&S模拟试卷
查看>>
ftp服务
查看>>
jenkins同平台发布
查看>>
LINUX入门基础
查看>>
Rancher 1.5全面发布!
查看>>
分布式缓存Redis Centos下单节点安装
查看>>
面试程序员总结的通病!
查看>>
添加自定义模板
查看>>
翘尾效应
查看>>
esxi
查看>>
Oracle常用函数
查看>>
SQL Server查询某字段在哪些表中
查看>>