问题 问答题

下列给定程序中函数fun的功能是:统计substr所指的字符串在str所指的字符串中出现的次数。 例如,若字符串为aass 1kaaas,子字符串为as,则应输出2。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> int fun(char *str, char *substr) { int i, j, k, num=0; /********** found**********/ for(i=0, str[i], i++) for(j=i, k=0; substr[k]==str[j]; k++, j++) /********** found**********/ If(substr[k+1]==’\0’) { num++; break; } return num; } main() { char str[80], substr[80]; printf("Input a string:"); gets(str); printf("Input a substfing: "); gets(substr); printf("%d\n", fun(str, substr)); }

答案

参考答案:(1)for(i=0; str[i]; i++) (2)if(substr[k+1]==’\0’)

解析:[考点] 本题考查:for循环语句和if条件语句的格式。for循环语句使用最为灵活,其一般形式为for(表达式1;表达式2;表达式3),注意表达式之间使用“;”相隔;在if条件语句中,if关键字需要区别大小写,不能混淆使用。关键字是由C语言规定的具有特定意义的字符串,也称为保留字。用户定义的标识符不应与关键字相同,并且关键字应小写。 先看循环条件for(i=0, str[i], i++),不难发现此处for循环语句的格式有误,其中表达式之间应以“;”相隔;同时很容易发现if条件语句处的关键字书写错误。

阅读理解

阅读理解。

     In the USA, there are many types of restaurants. Fast food restaurants are very famous. You can

find McDonald's and Kentucky Fried Chicken in many countries around the world. You look at a

menu above the counter(柜台), and say what you'd like to eat. You pay the person who serves you.

You take your food and sit down or take it away. There's no need to leave a tip"(小费).

     In a coffee shop you sit at the counter or at a table. You don't wait for the waitress to show you

where to sit. She usually brings you coffee when you sit down, You tell her what you'd like to eat and

she brings it to you. You pay the cashier as you leave.

     In a family restaurant the atmosphere is casual, but the waitress shows you where to sit. Often the

waitress tells you her name, but you don't need to tell her yours. If you don't eat everything, your

waitress gives you a doggy bag to take your food home. You add an extra fifteen percent to the bill as

a tip.

     In top class restaurants, you need a reservation (预定) and you need to arrive on time. The waiter

shows you where to sit.If you have wine, he may ask you to taste it. You can only refuse it if it tastes

bad, or if you don't like it. When you get your bill, check it and then add fifteen to twenty percent to it

as a tip for the waiter.

1.There are _____ types of restaurants here.

A.three          

B.four            

C.five            

D.six   

2.You pay the person who _____ at the fast food restaurant.

A.brings food to you                    

B.tells you her name

C.shows you the seat                    

D.you talk to    

3.We should sit _____ in a coffee shop.

A.near the door                        

B.in the corner    

C.at the counter                        

D.on the floor

4.In what kind of restaurant does the waitress often tell you her name?     

A.In a top class restaurant:              

B.In a fast food restaurant.  

C.In a coffee shop.                    

D.In a family restaurant.

5.How much do you need to tip in a top class restaurant?    

A.Ten percent.                        

B.Fifteen percent.

C.Thirty percent.                    

D.Forty percent.

选择题