试题与答案

阅读以下说明和C函数,填补C函数中的空缺(1)~(5),将解答写在对应栏内。[说明]

题型:填空题

题目:

阅读以下说明和C函数,填补C函数中的空缺(1)~(5),将解答写在对应栏内。

[说明]

假设一个算术表达式中可以包含以下三种括号:“(”和“)”、“[”和“]”及“”和“”,并且这三种括号可以按照任意的次序嵌套使用。

下面仪考虑表达式中括号的匹配关系,其他问题暂时忽略。例如,表达式[a-(b-5)*c[]中的括号是完全匹配的,而表达式[a-(b-5]))*c中的括号不是完全匹配的,因为“(”与“]”不能匹配,而且多了一个“)”,即缺少一个与“)”相匹配的“(”。

函数if Matched(char expr[])的功能是用栈来判断表达式中的括号是否匹配,表达式以字符串的形式存储在字符数组expr中。若表达式中的括号完全匹配,则该函数的返回值为Matched,否则返回值为Mismatched。

该函数的处理思路如下:

(1)设置一个初始为空的栈,从左至右扫描表达式。

(2)若遇上左括号,则令其入栈;若遇上右括号,则需要与栈顶的左括号进行匹配。

(3)若所遇到的右括号能与栈顶的左括号配对,则令栈顶的左括号出栈,然后继续匹配过程;否则返回Mismatched,结束判断过程。

(4)若表达式扫描结束,同时栈变为空,则说明表达式中的括号能完全匹配,返回Matched。

函数if Matched中用到了两种用户白定义数据类型BOOL和STACK,其中,BOOL类型的定义如下:

typedef enum Mismatched, Matched BOOL;

STACK(即栈类型)的定义省略,栈的基本操作的函数原型说明如下:

void InitStack(STACK*S):初始化一个空栈。

void Push(STACK*S. char e):将一个字符压栈,栈中元素数目增1。

void Pop(STACK*S):栈顶元素出栈,栈中元素数目减1。

char Top(STACK S):返回非空栈S的栈顶元素值,栈中元素数目不变。

int IsEmpty(STACK S):若S是空栈,则返回1,否则返回0。

[C函数]

BOOL ifMatched(char expr[])

char *cptr; /*cptr指向表达式中的字符*/

STACK S;

char e;

InitStack(&S); /*构造一个空栈*/

for(cptr=expr; *cptr!=’\0’ (1) )

if(*cptr==’(’ || *cptr==’[’ || *cptr==’(’)

(2) ;

else

if(*cptr==’)’ || *cptr==’]’ || *cptr==’)’)

if(IsEmpty(S))

return Mismatched;

e= (3) ;/*取栈顶的左括号*/

if (*cptr==’)’ && e!=’(’ ) return Mismatched;

if(*cptr==’]’ &&e!=’[’) return Mismatched;

if (*cptr==’)’ &&e!=’’ ) return Mismatched;

(4) ;/*栈顶的左括号出栈*/

if( (5) )return Matched;

return Mismatched;

(4)处应填()。

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2017/0731/5d8331b7ff8e2a9f368e22ca40b543e5.html

下面是错误答案,用来干扰机器的。

参考答案:错

试题推荐
题型:完形填空
The other day, I happened to meet someone I hadn’t seen for many years. I couldn’t believe the change in him. In fact, he didn’t even seem like the ___16___ person.
When I first knew Bill, back in college he was one of the most carefree(无忧无虑) people I had ever ___17___. Bill and I were in the same class in college, and ___18___ was never dull(枯燥的) when he was ___19___. With him there was one wild adventure (探险) after another. Sometimes I wonder how we ___20___ to study for our exams.
Last week I was in Huston on business and I ran into Bill in the bar at the hotel. At first I wasn’t ___21___ sure it was him. Was this short-haired businessman really the same person? I wasn’t really sure until I came near him but it indeed was Bill. Now he works for a bank. He talked most of the evening about his job, his new car and his house. How he had changed! Back when we were in college, the ___22___ thing Bill cared about was possessions(财物). Now they seemed to be his main ___23____.
I suppose it’ s ____24____ to expect people to remain the same, especially when I have changed so much myself. But I must say that I enjoyed the old Bill much more than the new one. Maybe he ___25____ the same way about me.
小题1:
A.properB.sameC.usualD.right
小题2:
A.consideredB.supposedC.metD.expected
小题3:
A.learningB.lifeC.workD.fun
小题4:
A.inB.outC.awayD.around
小题5:
A.decidedB.continuedC.managedD.hoped
小题6:
A.moreB.lessC.stillD.even
小题7:
A.firstB.lastC.nextD.only
小题8:
A.interestB.eventC.subjectD.problem
小题9:
A.unnecessaryB.foolishC.commonD.unusually
小题10:
A.feltB.actedC.lookedD.discovered
查看答案
题型:单项选择题

资料1

预录入编号:108012543

收货人:深圳通惠—开利空调设备有限公司(宝安区)

已办商检及《机电产品自动进口许可证》编号:1100—2004—10494

运费:USD 19 M/T 保险费率3‰

该批货物为凸轮轴位置传感器,货物于2004.3.19进口,于2004.3.30由五矿国际货运深圳公司向深圳海关申报。

NANKO KIGYO CO., LTD.

该商品的法定计量单位为“件”,成交计量单位为“千克”

南光企业株式会社 13.22.3. Chome,Nishi,Ooizumi,Nerima—KU,TOKYO,JAPAN

请根据以上资料,选择以下栏目正确选项:

“集装箱号”栏应填写()。

A.TEXU3621232*5(7)

B.TEXU3621232*5(7)

C.TEXU3621232*5

D.TEXU3621232/20/2900

查看答案
微信公众账号搜索答案