游客:  注册 | 登录 | 搜索 | 帮助
3s地带



标题: 一道c++编程题
fxrxhrfs
强风
Rank: 3



UID 3978
精华 0
积分 134
帖子 31
现金 124
贡献值 0
阅读权限 30
注册 2007-8-24
一道c++编程题
编写一个程序,能实现:

a) 求出字符串str2在字符串str1中首次出现的位置
b) 求出字符串str2在字符串str1中末次出现的位置
c) 判断输入的一字符串是否为回文
d) 判断输入的一全汉字字符串是否为回文;
e) 把从文件读入的若干个字符串中找出最长字符串并输出
f) 把从文件读入的若干个字符串按字典顺序排序 说明: 回文是指从左读和从右读都一样。例如“able was ere saw elba”、 “损人利己非己利人损”都是回文。

顶部
hipokih
强风
Rank: 3



UID 4186
精华 0
积分 106
帖子 24
现金 96
贡献值 0
阅读权限 30
注册 2007-8-24
// program2 .cpp
#i nclude<iostream.h>
#i nclude"astack.h"

void dblank(char *,char *);
void main(){
const int TRUE=1,FALSE=0;
Stack S;
char palstring[80],dblankstring[80],ch;
int i=0;
int ispalindrome=TRUE;
for(int i=0;(j<80)&&((ch=getchar())!EOF)&&(ch!='\n');j++)
palstring[j]=(char)ch;
paltring[j]='\n';
//input a string,and with '0'end
dblank(palstring,dblankstring);
while(dblankstring!=0){
S.Push(dblankstring);
i++;
}
while(!S.StackEmpty()){
ch=S.S.Pop();
if(ch!=dblankstring){
ispalindrome=FALSE;
break;
}
i++;
}
if(ispalindrome)
cout<<'\''<<palstring<<'\''<<"is apalindrome"<<endl;
else
cout<<'\''<<palstring<<'\''<<"is not apalindrome"<<endl;

}
void dblank(char * str,char * dblankstr){
char * pstr;
char * pdblankstr;
pstr=str;
pdblankstr=dblankstr;
while(*pstr!='\0'){
if(*pstr!='b'){
* dblankstr=* pstr;
dblankstr++;
}pstr++;
}
*dblankstr='\0';
}
// astack.h
#i nclude<iostream.h>
#i nclude<stdlib.h>
const int MaxSize=50;
class Stack{
private:
char slist[MaxSize];
int top;
public:
Stack(void){top=0; };
~Stack(void){};
void Push(const char &item);
char Pop(void);
int StackEmpty(void) const{ return top==0;};
int StackFull(void) const{return top==MaxSize;};
};
void Stack:ush(const char&item){
if(top==MaxSize)
cout<<"STACK OVERFLOW!"<<endl;
else {
slisr[top]=item;
top++;
}
}
char Stack:op(void){
if(top==0){
cout<<"an empty stack"<<endl;
return 0;
}
top--;
return slist[top];
}

  
顶部


 
当前时区 GMT+8, 现在时间是 2008-12-2 12:50 清除 Cookies - 联系我们 - 3S地带 - Archiver - WAP - 赣ICP备07006302号
Powered by Discuz! 5.5.0  © Processed in 0.027304 second(s), 6 queries , Gzip enabled