fzu 1001

qqmsn270601679 2010-03-04 08:32:18
Problem Description
An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.



Input
Input contains several cases.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.


Output
Your must output the value for each case, one per line.

Sample Input
2
1 1
4
1 2 3 2
Sample Output
1
2


为什么超时??

#include <iostream>
using namespace std;
int main()
{

int b,n,i,m,s;
while(scanf("%d",&n))
{
s=0;
m=0;
for(i=0;i<n;i++)
{
scanf("%d",&b);
s=s+b;
m+=i;
}

printf("%d\n",s-m);
}
return 0;
}
...全文
83 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqmsn270601679 2010-03-11
  • 打赏
  • 举报
回复
好像可以,解决了谢谢
logiciel 2010-03-04
  • 打赏
  • 举报
回复
while(scanf("%d",&n))
改为
while(scanf("%d",&n)!= EOF)

否则循环不会结束,因此超时。
xboy 2010-03-04
  • 打赏
  • 举报
回复
问题描述清晰一点,你的程序貌似没什么问题啊

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧