如下代码片段的输出是什么? int i = 10; while (i > 0) { i--; } printf ("%d ", i); i = 10; do { i--; } while (i > 0); printf ("%d", i);
A.1 1
B.1 0
C.0 1
D.0 0
A.1 1
B.1 0
C.0 1
D.0 0
A、[1, 9]
B、[1, 27]
C、[1, 27, 3125]
D、会报错
【程序5说明】
著名的四色定理指出任何平面区域图均可用四种颜色着色,使相邻区域着不同的颜色。本程序对给定的区域图找出所有可能的不超过四种颜色的着色方案。
程序中用1~4表示四种颜色。要着色的N个区域用0~N-1编号,区域相邻关系用 adj[][]矩阵表示,矩阵的i行j列的元素为1,表示区域i与区域j相邻;矩阵的i行j列的元素为0,表示区域i与区域j不相邻。数组color[]用来存储着色结果,color[i]的值为区域i所着颜色。
【程序5】
include<stdio.h>
define N 10
void output(int color[])/*输出一种着色方案*/
{ int i;
for(i=0;i<N;i++)
printf("%4d",color[i]);
printf("\n");
}
int back (int * ip,int color[])/*回溯*/
{ int c=4;
while(c==4){
if(*ip<=0)return 0;
--(*ip);
c=(1);
color[*ip]=-1;
}
return c;
}
/*检查区域i,对c种颜色的可用性*/
int colorOk(int i,int c,int [][N],int color[]}
{ int j;
for(j=0;j<i;j++)
if((2))
return 0;
return 1;
}
/*为区域i选一种可着的颜色*/
int select (int i,int c,int adj[][N],int color[])
{ int k;
for(k=c;k<=4;k++)
if(colorOK((3)))
return k;
return 0;
}
int coloring(int adj[][N])/*寻找各种着色方案*/
{ int color[N],i,c,cnt;
for(i=0;i<N;i++)color[i] =-1;
i=c=0;cnt=0;
while(1){
if((c=(4))==0){
c=back(&i,color);
if(c==0)return cnt;
}else{(5);i++;
if(i==N){
output(color);
++cnt;
c=back(&i,color);
}else c=0;
}
}
}
void main()
{ int adj[N][N]=
{{0,1,0,1,1,1,1,1,1,1},
{1,0,1,1,0,1,1,1,1,0},
{0,1,0,1,0,1,1,0,1,1},
{1,1,1,0,1,1,0,0,1,1},
{1,0,0,1,0,1,0,0,0,0},
{1,1,1,1,1,0,1,0,0,1},
{1,1,1,0,0,1,0,0,1,0},
{1,1,0,0,0,0,0,0,1,1},
{1,1,1,1,0,0,1,1,0,1},
{1,0,1,1,0,1,0,1,1,0}
};
printf("共有%d组解.\n",coloring(adj));
}
【说明】
该程序的功能是从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中,以行为单位对行中以空格或标点符号为分隔的所有单词进行倒排。最后把已处理的字符串(应不含标点符号)仍按行重新存入字符串数组xx中,最后把结果xx输出到文件OUT6.DAT中。
例如:原文:You He Me
I am a student.
结果:Me He You
student a am I
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
【函数】
include<string.h>
include<conio.h>
include<ctype.h>
include<stdio.h>
char xx[50] [80];
int maxline=0; /*文章的总行数*/
int ReaaDat(void);
void WriteDat(void);
void StrOL(void)
{
char * p1, * p2,t[80];
int i;
for(i=0;i<maxline;i++)
{ p1=xx[i];t[0]=0;
while(*p1)p1++;
while(p1>=xx[i])
{ while(!isalpha(*p1) &&p1!=xx[i])p1--;
p2=p1;
while((1))p1--;
if(p1==xx[i])
if(isalpha(*p1))p1--;
else if(!isalpha(*(p1+1)))break;
p2++;
(2);
strcat(t, p1+1);
strcat(t," ");
}
strcpy(xx[i],t);
}
}
void main()
{
if((3)) {
printf("数据文件in.dat不能打开!\n\007" );
return;
}
StroL();
writeDat();
getch();
} int ReadDat(void)
{
FILE * fp;
int i =0;
char * p;
if((fp=fopen("e:\a\in.dat"," r" ))==NULL)return 1;
while(fgets(xx[i],80,fp)!=NULL) {
p=strchr(xx[i],'\n')
if(p)*p=0;
i++;
}
maxline=(4)
fclose(fp);
return 0;
}
void WriteDat(void)
{
FILE * fp;
int i;
fp=fopen("e:\\a\\out6,dat","w");
for(i=0;i<(5);i++){
printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i])
}
fclose(fp)
}
B、# & & *
C、# && &*
D、# && &*#&
A、x: 5 i: 10
B、x: 5 i: 10
C、x: 4 i: 9
D、x: 4 i: 9
B、****** ******
C、****** ****** ****** ******
D、****** * * * * * * ******
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!