当前位置: 代码迷 >> C语言 >> [原创]9.8日标程&测试数据
  详细解决方案

[原创]9.8日标程&测试数据

热度:645   发布时间:2007-09-08 22:35:40.0
[原创]9.8日标程&测试数据
数据:


data.c

#include<stdio.h>
int main(void)
{
char s[1001]={0};
int i;
int n,temp;
int max=0,min=1001,sum=0;
FILE *input,*output;
input=fopen("data.in","r");
output=fopen("data.out","w");
fscanf(input,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(input,"%d",&temp);
if(!s[temp])
{
s[temp]=1;
sum+=temp;
if(temp>max) max=temp;
if(temp<min) min=temp;
}
else { i--; n--; }
}
fprintf(output,"%d\n",n);
for(i=0;i<1001;i++) if(s[i]) fprintf(output,"%d ",i);
fprintf(output,"\n%d %d",max-min,sum/n);
fclose(input);
fclose(output);
return 0;
}

[此贴子已经被作者于2007-9-8 22:56:36编辑过]

搜索更多相关的解决方案: 数据  

----------------解决方案--------------------------------------------------------
words.c

#include<stdio.h>
char s[101][101]={0};
char sx[12][2]={{1,0},{-1,0},{2,0},{-2,0},{1,1},{-1,1},{1,-1},{-1,-1},{0,1},{0,-1},{0,2},{0,-2}};
int n,m;
int c=0;
void dfs(int x,int y)
{
int i,j;
for(i=0;i<12;i++)
if(sx[i][0]+x>-1 && sx[i][0]+x<n && sx[i][1]+y>-1 && sx[i][1]+y<m && s[sx[i][0]+x][sx[i][1]+y]=='x')
{
s[sx[i][0]+x][sx[i][1]+y]=0;
dfs(sx[i][0]+x,sx[i][1]+y);
}
}
int main(void)
{
int i,j,k;
FILE *input,*output;
input=fopen("words.in","r");
output=fopen("words.out","w");
fscanf(input,"%d%d",&n,&m);
for(i=0;i<n;i++) fscanf(input,"%s",s[i]);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(s[i][j]=='x')
{
c++;
dfs(i,j);
}
fprintf(output,"%d",c);
fclose(input);
fclose(output);
return 0;
}


----------------解决方案--------------------------------------------------------
sky.c
#include<stdio.h>
int s[22]={0};
int t[21]={0};
int best=0;
int main(void)
{
FILE *input,*output;
char temp;
int i,k,j;
int n;
int x=0;
int max1=0,max2;
input=fopen("sky.in","r");
output=fopen("sky.out","w");
for(i=1;i<21;i++) if(fscanf(input,"%d%c",&s[i],&temp)==EOF) break;
n=i;
for(i=n;i>0;i--)
{
t[i]=1;
for(j=i+1;j<=n;j++)
if(s[j]<=s[i] && 1+t[j]>t[i]) t[i]=t[j]+1;
if(t[i]>t[best]) best=i;
}
fprintf(output,"%d,",t[best]-1);
while(1)
{
for(i=1;i<=n;i++) if(s[i]!=0) goto next;
break;
next:
for(i=1;i<=n;i++) if(s[max1]<s[i]) max1=i;
while(1)
{
max2=max1+1;
for(i=max2;i<=n;i++) if(s[max2]<s[i]) max2=i;
s[max1]=0;
for(i=max1;i<=n;i++) s[i]=s[i+1]; n--;
max2--;
max1=max2;
if(s[max2]==0) break;
}
x++;
}
fprintf(output,"%d",x-1);
fclose(input);
fclose(output);
return 0;
}
----------------解决方案--------------------------------------------------------
moon.c

#include<stdio.h>
struct
{
int v;
int m;
} s[3000][341]={0};
int v,n;
int now,nowx;
int countline[3001];
FILE *input,*output;
void dfs(int countv,int countm)
{
int vx,mx,nx;
int i;
fscanf(input,"%d%d%d",&vx,&mx,&nx);
n--; vx/=10;
countv+=vx*mx;
countm+=vx;
s[now][nowx].v=countv;
s[now][nowx].m=countm;
nowx++;
for(i=0;i<nx;i++) dfs(countv,countm);
}
int main(void)
{
int i,j,k;
int temp,tempmax;
input=fopen("moon.in","r");
output=fopen("moon.out","w");
fscanf(input,"%d%d",&v,&n);
v/=10;
while(n) { nowx=0; dfs(0,0); now++; }
for(i=0;i<now;i++)
for(j=v;j>0;j--)
{
tempmax=0;
for(k=0;s[i][k].v;k++)
if(s[i][k].m<=j && (temp=s[i][k].v+countline[j-s[i][k].m])>countline[j]) if(tempmax<temp) tempmax=temp;
if(countline[j]<tempmax) countline[j]=tempmax;
}
fprintf(output,"%d",countline[v]*10);
fclose(input);
fclose(output);
return 0;
}

----------------解决方案--------------------------------------------------------
count.c

#include<stdio.h>
int s[10001];
void qsort(int key[],int low,int high)
{
int i=low,j=high,tag;
if(i<j)
{
tag=key[low];
do
{
while(tag<key[j] && i<j) j--;
if(i<j)
{
key[i]=key[j];
i++;
while(tag>=key[i] && i<j) i++;
if(i<j)
{
key[j]=key[i];
j--;
}
}
} while(i<j);
key[i]=tag;
qsort(key,low,j-1);
qsort(key,i+1,high);
}
}
int main(void)
{
int m;
int n;
int i,j,k;
int temp;
FILE *input,*output;
input=fopen("count.in","r");
output=fopen("count.out","w");
fscanf(input,"%d%d",&n,&m);
for(i=1;i<=n;i++) fscanf(input,"%d",&s[i]);
for(i=0;i<m;i++)
{
int max=n;
for(j=n-1;j>0;j--)
{
if(s[j]<s[max])
{
for(k=j+1;k<=n;k++) if(s[k]<s[max] && s[k]>s[j]) max=k;
temp=s[max];
s[max]=s[j];
s[j]=temp;
qsort(s,j+1,n);
break;
}
else max=j;
}
}
for(i=1;i<n;i++) fprintf(output,"%d ",s[i]); fprintf(output,"%d",s[n]);
fclose(input);
fclose(output);
return 0;
}

----------------解决方案--------------------------------------------------------
不是按顺序发的,大家看文件名就知道对应的题目了
----------------解决方案--------------------------------------------------------

太长见识了,虽然目前个人只得10分……

希望以后多搞这样的活动,促进大家进步!

感谢几位主持人斑竹,辛苦了~


----------------解决方案--------------------------------------------------------