一道acm入门题想知道为什么TLE了
Time Limit: 1000 mSec Memory Limit : 65536 KB
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 <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,f,j=0;
while(scanf("%d",&n)!=EOF){
int *a = (int*)malloc(n*sizeof(int));
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
for(f=i+1;f<n;f++){
if(a[i]==a[f]){
j=a[i];
}
}
}
printf("%d",j);
free(a);
}
return 0;
}