Jump to: Sidebar, Content

Discuss 明明的随机数

Current

(2 in total)

by yhnglfw

yhnglfw

at 2010-06-18 22:50:31

现在终于过了

by yhnglfw

yhnglfw

at 2010-06-18 22:48:24

测试数据都不符合题意啊!做了半天。


/*
PROB:random
LANG:.c
*/

#include <stdio.h>
#include <stdlib.h>
int n;
int temp;
int temp2;
int i,j=0;
int s[1001];
int count=0;
int r[1001];
FILE *fp1=NULL;
FILE *fp2=NULL;
/*---------------------------------------------------*/
int main()
{

fp1=fopen("random.in","r");
if(fp1==NULL)
{
printf("Erorr! Read Faild.\n");
exit(0);
}
fp2=fopen("random.out","w");
if(fp2==NULL)
{
printf("Erorr! Write Faild.\n");
exit(0);
}
for(i=0;i<1001;i++)
{
s[i]=2;
}
/*----------------------------------------------------*/
fscanf(fp1,"%2d",&n);

for(i=0;i<n;i++)
{
fscanf(fp1,"%d",&temp);
s[temp]=1;
}
for(i=0;i<1001;i++)
{
if(s[i]==1)
{
j++;
count=count+1;
r[j]=i;
}
}
/*----------------------------------------------------*/
for(j=0;j<count;j++) 

for (i=0;i<count-j;i++) 
if (r[i]>r[i+1]) 

temp2=r[i]; 
r[i]=r[i+1]; 
r[i+1]=temp2;

}
/*----------------------------------------------------*/
fprintf(fp2,"%d",count);
for(i=1;i<count;i++)
                    fprintf(fp2,"%d ",r[i]);
                    fprintf(fp2,"%d\n",r[i]);
/*----------------------------------------------------*/
fclose(fp1);
fclose(fp2);
return 0;
}




正确的输入格式是
第一行:n
第二行:n个整数
正确的输出格式是
第一行:不重复的的数的个数
第二行:生序排列的不重复的数
第三行:空行


实际测试文件都不符合啊!

New

You can post after log in

You can submit after log in