问题 问答题

现有一个10个人100行的选票数据文件in.dat,其数据存放的格式是每条记录的长度均为10位,第一位表示第一个人的选中情况,第二位表示第二个人的选中情况,依此类推;内容均为字符0和1,1表示此人被选中,0表示此人未被选中,若一张选票人数大于等于8或者小于等于2个人时被认为无效的选票。给定函数ReadDat()的功能是把选票数据读入字符串数组xx中。请编制函数CountRs()来统计每个人的选票数并把得票数依次存入yy[0]到yy[g]中。把结果yy输出到文件out.dat中。
注意:部分源程序给出如下。
请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
[试题源程序]
#include<stdio.h>
char xx[100][11];
int yy[10];
int ReadDat(void);
void WriteDat(void);
void CountRs(void)


void main()

int i;
for(i=0;i<i0;i++)yy[i]=0;
if(ReadDat())

printf("can not open the file IN.DAT!\n\007");
return;

CountRs();
WriteDat();

int ReadDat(void)

FILE*fp;
int i:
if((fp=fopen("IN.DAT","r"))==NuLL)return 1;
for(i=0;i<100;i++)
if(fgets(xx[i],12,fp)==NULL)return 1;
xx[i][10]=’\0’;

fclose(fp);
return 0;

void WriteDat(void)

FILE*fp;
int i:
fp=fopen("OUT.DAT,"w");
fol(i=0;i<10;i++)

fprintf(fp,"%d\n",yy[i]);
printf("第%d个人的选票数=%d\n",i+1,yy[i]);

fclose(fp);

答案

参考答案:void CourtRs(void)
{
int i,j,cnt;
for(i=0;i<100;i++) /*遍历数组xx的每一行*/
{
cnt=0; /*计数值清0*/
for(j=0;j<10;j++) /*第一遍扫描统计该行所选人数*/
if(x[i][j]==’1’) /*若该位被选中,则计数值增1*/
cnt++:
if(cnt<8&&cnt>2) /*若该张选票人数在2到8个人*/
for(j=0;j<10;j++) /*遍历所有选票,并增加相应的计数值*/
if(xx)[[i][j]==’1’)
yy[j]++;
}
}

解析: 本题主要考查的是选票问题。首先用for循环和变量i遍历每一张选票,也就是每一行,对于某行xx[i]使用for循环和变量j遍历该行的每个元素,使用变量cnt统计该行所选的人数,也就是元素值为1的个数。如果该行所选人数cnt小于8并且大于2,则该选票有效,再次遍历这一行,如果选中,则第j个人的选票数yy[j]就加1。遍历完所有行后得到的yy[j]就是第j个人的有效的选票数。

阅读理解

阅读理解。

                                                                      Quick Service

     A man took a pair of shoes to a shoe repair shop and said to the shoemaker, "I'd like you to repair these

shoes for me, please." 

     "Certainly, sir." the shoemaker said.

     "When will they be ready?" the man asked.

     "I'm a bit busy, but they will be ready for you on Thursday," he said.

     "That's fine." the man said and left the shop.

     The next morning he received a letter, offering him a job in another country. Within 24 hours he was on

an airplane to his new job.

     Twenty years passed and he returned to his hometown.

     He remembered his shoes.

     "They were a good pair of shoes," he thought,"I wonder if the shoemaker is still there and still has them.

I'll go and see." The same shop, although he was an old man by now.

     "Good morning." he said to the shoe maker, "Twenty years ago, I brought in a pair of shoes. Do you still

have them?"

     "Name?" the old shoemaker asked.

     "Smith." the man said.

     "I'll go and see. They may be in the back."

     The shoemaker went out to the back of his shop and a few minutes later returned, carrying a pair of shoes.

     "Here they are." he said, "One pair of brown shoes. I'm a bit busy now, but they'll be ready on Thursday."

1. Why did the man go to a shoemaker? [ ]

A. They were old friends.

B. He wanted him to make a new pair of shoes.

C. He wanted him to repair a pair of shoes.

D. He had a very old pair of boots. He wanted to repair it.

2. Why didn't the man return to the shoe repair shop on Thursday? [ ]

A. He forgot.

B. He went to another country.

C. He was too busy.

D. He knew the shoes would not be ready.

3. The man was away from his hometown ____. [ ]

A. until Thursday

C. until the next morning

C. for about 20 years

D. for a few days

4. What did the man do when he returned to his hometown? [ ]

A. He looked for a new job.

B. He bought a new pair of shoes.

C. He visited all his friends.

D. He returned to the shoemaker.

5. The man finally found that ____. [ ]

A. his shoes were still there, but the shoemaker didn't repair them

B. his shoes were not there

C. the shoemaker repaired the shoes

D. the shoemaker lost the shoes

选择题