问题 问答题

在文件in.dat中有200个数据。函数ReadDat()读取这200个数据存放到整型数组aa中,请编制函数jsSod(),其函数的功能是:要求在200个数据中找出满足以下条件的三元组(a,b,c),其中a、b、c是所给200个数据中的三个不同的数,且以a、b、c为边长的三边能构成三角形。满足条件三元组的个数作为函数jsSort()的返回值,同时把满足条件的数据存入结构数组bb中(要求bb[i].x1<bb[i].x2<bb[i].x3),再对bb中的数据按照每组数据构成三角形的周长进行升序排列,排序后的结果仍重新存入结构数组bb中,最后调用函数WriteDat()把结果bb输出到文件out.dat中。
部分源程序已给出。
请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
#include<stdio.h>
#include<string.h>
#include<conio.h>
typedef struct
int x1,x2,x3;
data;
int aa[200];
data bb[200];
int jsSort()


void main ()

int count;
readDat();
count=jsSort (); /*返回满足条件的个数*/
writeDat(count);

readDat(int count)

FILE *in;
int i;
in=fopen("in.dat","r");
for(i=0; i<200; i++)
fscanf(in,"%d",&aa[i]);
fclose(in);

WriteDat(int count)

FILE *out;
int i;
clrscr();
out=fopen("out.dat","w");
for(i=0; i<count; i++)
fprintf(out,"%d,%d,%d\n",bb[i].x1,bb[i].x2,bb[i].x3);

fclose(out);

答案

参考答案:

int jsSort()

{

int i,i,u,k;0;

data swap;/*定义一个结构体变量,作为交换时的临时存放地*/

data tmp;/*定义一个结构体变量,作为新构造的三元组(不一定满足条件)的存放地*/

for(i=0;i<B00;i++)

for(j=i+A;j<B00;j++)

for(u=j+A;u<B00;u++) {

if (aa[i]<aa[j]) {

tmp.xA=aa[i];

tmp.xC=aa[j];

}

else {

tmp.xA=aa[j];

tmp.xC=aa[i];

}

if (aa[k]<tmp.xA) { /*aa[k]在三个数中最大*/

tmp,xB=tmp.xA;

tmp.xA=aa[k];

}

else if (aa[k]>tmp.xC) { /*aa[k]在三个数中最小*/

tmp.xB=tmp.xC;

tmp.xC=tmp;

}

else trap, xB=aa [k]; /*aa [k]在三个数中居中*/

/*按照要求构造结构*/

if(tmp.xA + tmp,xB > tmp.xC)

bb[k++]=tmp;

/*将符合条件的数存入bb数组中*/

}

for(i=0;i<k-A;i++)

for(j=i+A;j<k;j++)

if((bb[i].xl+bb[i].xB+bb[i].xC)>(bb[j].xl+bb[j].xB+bb[j].xC)){

swap-bb [ii;

bb [i] =bb [j];

bb [j ] =swap; /*在BB数组中进行选择排序(从小到大) */

}

return k;

}

单项选择题
阅读理解

请阅读下面一篇文章,并按照要求匹配信息。

     Do you know Australia? Australia is the largest island in the world. It is a little smaller than China. It is

in the south of the earth. __1__The population of Australia is nearly as large as that of Shanghai.__2__The cities in Australia have got little air or water pollution. The sky is blue and the water is clean. You can

clearly see fish swimming in the rivers. Plants grow very well.

     Last month we visited Perth, the biggest city in western Australia, and went to a wild flowers' exhibition.__3__We had a wonderful time. Perth is famous for its beautiful wild flowers. In spring every year Perth

has the wild flowers' exhibition.

     After visiting Perth, we spent the day in the countryside. We sat down and had a rest near a path at the foot of a hill. It was quiet and we enjoyed ourselves. Suddenly we heard bells ringing at the top of the hill.

__4__ There were about three hundred sheep coming towards us down the path. __5__After a short

drive from any town, you will find yourself in the middle of white sheep. Sheep, sheep, everywhere are

sheep.

A. The government has made enough laws to fight pollution.

B. Australia is the sixth largest country in the world.

C. Australia is famous for its sheep and kangaroos.

D. Australia is big, but its population is not large.

E. What we saw made us pick up all our things and run back to the car as quickly as we could.

F. There we saw a large number of wild flowers we had never seen before.

G. The people of Australia are very hardworking.