问题 填空题

下列给定程序中,函数fun()的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为abcdabfab,t所指字符串的内容为ab,则函数返回整数3。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构. 试题程序: #include <conio.h> #include <stdio.h> #include <string.h> int fun (char *s, char *t) {int n; char *p, *r;n=0;while(*s) {p=s; r=t; while (*r) /**************found**************/ if(*r==*p) {r++; p++} else break; /*************found**************/ if(r==’\0’) n++; s++; }return n; } main() {char s[100], t[100]; int m;clrscr();printf("\nPlease enter string s: "); scanf ("%s",s);printf("\nPlease enter substring t: "); scanf ("%s",t);m=fun (s,t);printf("\nThe result is: m=%d\n", m); }

答案

参考答案:错误:if(*r==*p) {r++;p++} 正确:if(*r==*p) {r++;p++;}

解析:(2) 错误;if(r==’\0’) 正确:if(*r==’\0’) 从字符串s中找出于串t的方法是:从第一个字符开始,对字符串进行遍历;若s串的当前字符等于t串的第1个字符,两字符串的指针自动加1,继续比较下一个字符;若比较至字符串t的结尾,则跳出循环;若s串的字符和t串的字符不对应相同,则继续对下一个字符进行处理。

多项选择题
阅读理解

阅读理解。

     Visitors to Britain may find the best place to sample local culture is in a traditional pub. But these friendly

pubs can be dangerous places of potential gaffes (失礼) for the newcomers.

     A team of researchers have discovered some of the unknown customs of British pubs-starting with the

difficulty of getting a drink. Most pubs have no waiters-you have to go to the bar to buy drinks. A group of

Italian youths waiting 45 minutes before they realized they would have to fetch their own. This may sound

inconvenient, but there is a hidden purpose.

     Pub culture is designed to promote sociability (社交) in a society known for its reserve. Standing at the

bar for service allows you to chat with others waiting to be served. The bar counter is possibly the only site

in the British Isles in which friendly conversation with strangers is considered entirely suitable and really quite

normal behavior. "If you haven't been to a pub, you haven't been to Britain." This tip can be found in a booklet,

Passport to the Pub: The Tourists' Guide to Pub Etiquette, a customers' rule of conduct for those wanting to

sample "a central part of British life and culture".

     The trouble is that if you do not follow the local rules, the experience may fall flat. For example, if you are

in a big group, it is best if only one or two people go to buy the drinks. Nothing annoys the regular customers

and bar staff' more than a group of strangers blocking all access to the bar while they chat and hesitate about

what to order.

1. The underlined word "sample" in the first paragraph probably means "_____".

A. taste

B. experience

C. test

D. record

2. The culture of pub in Britain is developed to _____.

A. encourage people to communicate with each other

B. encourage more people to consume drinks

C. attract more tourists to the pubs

D. form its own character of culture

3. If you don't follow the local rules in a pub, _____.

A. you won't buy good local drinks

B. you may annoy the regular customers and bar staff

C. you may fail to feel the local culture

D. you might get into a dangerous place

4. What may be the best title for the passage?

A. Self-service Pubs in Britain

B. British Local Pubs: Special Chat Places

C. Local Pub Culture in Britain

D. Manners in British Local Pubs