问题 问答题

请编写函数fun(),该函数的功能是判断字符串是否为回文,若是则函数返回1,主函数中输出YES:否则返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。
例如:字符串LEVEL是回文,而字符串123312就不是回文。
注意;部分源程序已存在文件test26_.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test26_2.cpp的内容如下:
#include<iostream.h>
#include<stdio.h>
#define N 80
int fun(char*str)


void main()
char s[N];
cout<<"Enter a string:"<<endl;
getss);
cout<<"\n\n";
puts(s);
if(fun(s))
cout<<"YES\n";
else
cout<<"NO\n";

答案

参考答案:
int fun(char*str)
{int i,n=O,fg=1;
char*p=str;
while(*p)
{n++; p++;}
for(i=0;i<n/2;i++)
if(str[i]==str[n-1-i]) ;
else
{fg=O;break;}
return fg;
}

解析:解答本题的主要思路是:首先要利用循环中指针的移动来求得字符串的长度n,然后用一个for循环依次取得数组中的前半部分元素,用取得的前半部分内的元素逐个与后半部分内的对应位置的元素进行比较,如果相同,不做任何工作,接着取下一个元素,继续比较:如果不相同,可以判断该字符串肯定不是回文,就给标志变量fg赋值0(fg的初始值为1)。最终把fg作为函数的返回值返回(fg值为1表明是回文,fg值为0表明不是回文)。

单项选择题
阅读理解

  Friendship can deeply affect the physical and mental health of both men and women. Studies show that people who have no friends or who are lonely,are more likely to die earlier,get sick more often and suffer greater physical wear and tear(折磨)than those who have a support system of friends.

  Sometimes,family members may be more likely to give you advice or tell you what you don’t want to hear. It may not be as good as a friend who will listen to you and guide you,but support your decisions anyway. The most important elements about friendship are those who suffer support and do not judge your decisions based on society.

  One reason for the link between social support and good health practice seems to be that people who feel cared for by others are less stress-out and are protected against the symptoms(症状)of depression and loneliness.

  Generally,women benefit most because of how they deal with stress. Women are more social in how they deal with stress than men, while men are more likely to have a“fight or flight”reaction.

  Women also tend to have larger,denser social network,in which more people know each other and help each other, while men typically have smaller groups of friends and will rely on their wives or other important people for more support. While all these affect people psychologically(心理上),friendship brings comfort that reduces the ill effects of stress, and the sex difference also contributes to the difference in the length of one’s life time.

63.In the author’s opinion,a real friend should _____.

A.tell you what to do even if you refuse to hear it

B.try to persuade you to change your mind quickly

C.judge your decision according to his/her experience

D.give you advice but respect your own decision

64.Women benefit more from friendship than men because_____.

A.women are always cared for by more people than men

B.women are usually less stress—out when staying with others

C.women are more likely to solve problems with friends’ help

D.women can always keep more long-life friendship than men

65.According to the passage we can infer that _____.

A.it’s good for women to tell men what they should do or not

B.friends are always more important than family members

C.men don’t want to share their problems with many people

D.the trend that women can live longer makes them more relaxed

66.This passage mainly talks about _____.

A.why people should develop friendship

B.when friendship affects people’s health

C.people’s different attitudes towards friendship

D.the friendship which can make people live longer