题目难度还可以,排名第三,成绩330,但是与第一和第二还有一定差距,努力啊
我的代码:
game.c
#include<stdio.h>
#include<string.h>
int main(void)
{
int i;
int n,x;
int m=1;
char s[200];
FILE *in,*out;
in=fopen("game.in","r");
ut=fopen("game.out","w");
fscanf(in,"%d%s",&n,s);
if((x=strlen(s))!=n)
fprintf(out,"error!\n");
else
{
for(i=0;i<x;i++)
{
if(s[i]=='r') m++;
}
fprintf(out,"%d\n",m);
}
fclose(in);
fclose(out);
return 0;
}
love.c
#include<stdio.h>
typedef struct
{
int x; /*数字*/
int n;
}DATA;
/*
void qsort(int low,int high,DATA key[])
{
int i=low,j=high;
DATA tag;
if(i<j)
{
tag=key[low];
do
{
while(tag.x<key[j].x && i<j) j--;
if(i<j)
{
key[i]=key[j];
i++;
while(tag.x>=key[i].x && i<j) i++;
if(i<j)
{
key[j]=key[i];
j--;
}
}
}
while(i<j);
key[i]=tag;
qsort(low,i-1;key);
qsort(j+1,high,key);
}
}
*/
int main(void)
{
int i,j,k;
DATA line[27001]={0};
int n;
int max=0;
FILE *in,*out;
in=fopen("love.in","r");
ut=fopen("love.out","w");
fscanf(in,"%d",&n);
for(i=0;i<n;i++) fscanf(in,"%d",&line[i].x);
for(i=n-1;i>=0;i--)
{
line[i].n=1;
for(j=i+1;j<n;j++)
{
if(line[i].x<=line[j].x)
if(line[j].n+1>line[i].n)
line[i].n=line[j].n+1;
}
if(line[i].n>max) max=line[i].n;
}
fprintf(out,"%d",max);
fclose(in);
fclose(out);
return 0;
}
score.c
#include<stdio.h>
#include<stdio.h>
char s[40];
int jian(char a[40],char b[40])
{
int i,x;
int lena,lenb;
memset(s,0,sizeof(s));
lena=strlen(a);
lenb=strlen(b);
for(i=0;i<40;i++)
{
if(a[i])
a[i]-='0';
if(b[i])
b[i]-='0';
}
x=39-lena;
lena--;
for(i=39;i>x;i--,lena--) a[i]=a[lena];
for(i=0;i<=x;i++) a[i]=0;
x=39-lenb;
lenb--;
for(i=39;i>x;i--,lenb--) b[i]=b[lenb];
for(i=0;i<=x;i++) b[i]=0;
i=0;
while(a[i]==0) i++;
for(;i<39;i++) { a[i]--; a[i+1]+=10; }
for(i=0;i<40;i++)
s[i]=a[i]-b[i];
for(i=39;i>0;i--)
{
s[i-1]+=s[i]/10;
s[i]%=10;
}
}
int main(void)
{
int i,k;
int n;
char max[3][40]={0};
char my[3][40]={0};
char temp[40]={0};
int r,t;
FILE *in,*out;
in=fopen("score.in","r");
ut=fopen("score.out","w");
fscanf(in,"%s%s%s",max[0],max[1],max[2]);
strcpy(my[0],max[0]);
strcpy(my[1],max[1]);
strcpy(my[2],max[2]);
fscanf(in,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(in,"%s",temp);
r=strcmp(temp,max[0]);
t=strlen(temp)-strlen(max[0]);
if((t>0)||((r>0)&&(t==0))) { strcpy(max[0],temp); }
fscanf(in,"%s",temp);
r=strcmp(temp,max[1]);
t=strlen(temp)-strlen(max[1]);
if((t>0)||((r>0)&&(t==0))) { strcpy(max[1],temp); }
fscanf(in,"%s",temp);
r=strcmp(temp,max[2]);
t=strlen(temp)-strlen(max[2]);
if((t>0)||((r>0)&&(t==0))) { strcpy(max[2],temp); }
}
for(k=0;k<3;k++)
{
if(!strcmp(max[k],my[k])) fprintf(out,"0 ");
else
{
jian(max[k],my[k]);
i=0;
while(s[i]==0) i++;
for(;i<40;i++) fprintf(out,"%d",s[i]);
fprintf(out," ");
}
}
fprintf(out,"\n");
fclose(in);
fclose(out);
return 0;
}
sos.c
#include<stdio.h>
int main(void)
{
int i,j,k;
int n;
int x[30][30];
int t,c;
FILE *in,*out;
in=fopen("sos.in","r");
ut=fopen("sos.out","w");
fscanf(in,"%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
fscanf(in,"%d",&x[i][j]);
if(x[i][j]==1) x[i][j]=-1; else x[i][j]=1000;
}
x[0][0]=1;
c=n-1;
while(x[c][c]==1000)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(i>0)
if(x[i-1][j]!=-1)
if((t=x[i-1][j]+1)<x[i][j])
x[i][j]=t;
if(i<c)
if(x[i+1][j]!=-1)
if((t=x[i+1][j]+1)<x[i][j])
x[i][j]=t;
if(j>0)
if(x[i][j-1]!=-1)
if((t=x[i][j-1]+1)<x[i][j])
x[i][j]=t;
if(j<c)
if(x[i][j+1]!=-1)
if((t=x[i][j+1]+1)<x[i][j])
x[i][j]=t;
}
}
fprintf(out,"%d\n",x[c][c]);
fclose(in);
fclose(out);
return 0;
}
其中love.c过3个点,其余7个点超时或崩溃
另外3个题均AC全部点