我个人建议固定一些编程序题目会好一些。
谁有强殖装甲第二部,可以Q我460054868
第4题还没做出来,现做后面的吧。
第5题:
main()
{int i=0,j,NUM,N,a[16];
char note[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
clrscr();
for(j=0;j<16;j++) a[j]=0;
printf("Please input the NO.");scanf("%d",&NUM);
printf("Transform to ?");scanf("%d",&N);
while(NUM != 0)
{a[15-i]=NUM % N;
NUM=(NUM-a[15-i])/N;
i=i+1;}
printf("NUM=%dx",N);
for(i=0;i<16;i++) if(a[i]) {j=i;break;}
for(;j<16;j++) printf("%c",note[a[j]]);
getch();
}
第6题
#define NUM 9
main()
{int i,j,k=1,m,mi,mj,a[NUM][NUM],ind[4]={NUM-1,NUM-1,0,1};
clrscr();
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{a[i][j]=k;k++;}
/* back*/
printf("back:\n");
for(i=NUM-1;i>=0;i--)
for(j=NUM-1;j>=0;j--)
{printf("%4d",a[i][j]);
if(j==0) printf("\n");
}
printf("\n");
/* snake */
printf("snake:\n");
k=1;
for(m=0;m<=(NUM-1)*(NUM-1);m++)
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{if((i+j)==m)
{if(m%2==0)
{a[i][j]=k;k=k+1;}
else
{a[j][i]=k;k=k+1;}
}
}
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{printf("%4d",a[i][j]);
if(j==NUM-1) printf("\n");}
printf("\n");
/*cycle*/
printf("cycle:\n");
k=1;i=0;j=0;
while(ind[0]>=ind[2])
{while(i<=ind[0])
{a[i][j]=k;i++;k++;}
ind[0]--;i--;j++;
while(j<=ind[1])
{a[i][j]=k;j++;k++;}
ind[1]--;j--;i--;
while(i>=ind[2])
{a[i][j]=k;i--;k++;}
ind[2]++;i++;j--;
while(j>=ind[3])
{a[i][j]=k;j--;k++;}
ind[3]++;j++;i++;}
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{printf("%4d",a[i][j]);
if(j==NUM-1) printf("\n");}
printf("\n");
getch();
}
18题的,以前是做过个青蛙跳的,题目一样 大家需要的话我就贴下注释了....代码运行可以
#include <stdio.h>
#include <stdlib.h>
#define DEBUG 0
#define TRUE 1
#define FALSE 0
typedef struct _Frog
{
int spaceflag;//1 = have space, -1=no space
int direct;//1 = right, 0 = no direct, -1 = left
char* id;
int address;
}Frog;
Frog frog[7];
static void Printf(Frog* frog);
static int Act(Frog* frog);
static int Review(Frog* frog);
int main()
{
int a,i,x;
x=0;
frog[0].spaceflag=-1;
frog[0].direct=1;
frog[0].id="A1";
frog[0].address=0;
frog[1].spaceflag=1;
frog[1].direct=1;
frog[1].id="A2";
frog[1].address=1;
frog[2].spaceflag=1;
frog[2].direct=1;
frog[2].id="A3";
frog[2].address=2;
frog[3].spaceflag=-1;
frog[3].direct=0;
frog[3].id="space";
frog[3].address=3;
frog[4].spaceflag=1;
frog[4].direct=-1;
frog[4].id="B4";
frog[4].address=4;
frog[5].spaceflag=1;
frog[5].direct=-1;
frog[5].id="B5";
frog[5].address=5;
frog[6].spaceflag=-1;
frog[6].direct=-1;
frog[6].id="B6";
frog[6].address=6;
while(1)
{
Printf(frog);
a=Act(frog);
system("cls");
if(DEBUG)
{
for(a =0;a<7;a++)
{
printf("%d\n",(frog+a)->spaceflag);
}
}
x=0;
for(i=0;i<7;i++)
{
if((frog+i)->spaceflag == -1)
{
x=x+1;
}
}
if(x==7)
break;
}
;
printf("congratulations, pass\n");
}
int Act(Frog* frog)
{
int y,i;
printf("please input id:");
scanf("%d", &y);
if(y<4)
y=y-1;
if(((frog+3)->address==y)||(y>6))
{
printf("Id error,don't move\n");
}
else
{
if((frog+y)->spaceflag == 1)
{
if(((frog+y)->direct == 1)&&((frog+y)->address<(frog+3)->address))
{
if(((frog+3)->address)-((frog+y)->address) == 1)
{
(frog+y)->address = (frog+y)->address+1;
(frog+3)->address = (frog+3)->address-1;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
else
{
(frog+y)->address = (frog+y)->address+2;
(frog+3)->address = (frog+3)->address-2;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
}
else
if(((frog+y)->direct == -1)&&((frog+y)->address>(frog+3)->address))
{
if(((frog+y)->address)-((frog+3)->address) == 1)
{
(frog+y)->address = (frog+y)->address-1;
(frog+3)->address = (frog+3)->address+1;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
else
{
(frog+y)->address = (frog+y)->address-2;
(frog+3)->address = (frog+3)->address+2;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
}
else
{
printf("Id error,don't move\n");
return(1);
}
}
else
{
printf("Id error,don't move\n");
return(1);
}
}
return(0);
}
void Printf(Frog* frog)
{
int x,y;//x = address, y = id
for(x=0;x<7;x++)
{
for(y=0;y<7;y++)
{
if((frog+y)->address==x)
{
printf("%s\t", (frog+y)->id);
}
}
}
}