#include <iostream>
#include <string>
using namespace std;
int findchar(const char *s,const char *t);
int main(int argc, char* argv[])
{
string s;
string t;
cout<<"输入第一个字符串(以输入#结束): \b";
getline(cin,s,'#');
cout<<"输入第一个字符串(以输入#结束): \b";
getline(cin,t,'#');
int pos = findchar(s.c_str(),t.c_str());
if (pos == 0)
{
cout<<"查找失败!"<<endl;
}
else
{
cout<<s[pos]<<"出现在S的最右边第"<<pos<<"个"<<endl;
}
return EXIT_SUCCESS;
}
int findchar(const char *s,const char *t)
{
int pos = 0;
int lenS = strlen(s);
int lenT = strlen(t);
for (int i=0; i<lenT ; ++i)
{
for (int j=lenS; j>=0; --j)
{
if (s[j] == t[i])
{
pos = lenS-j;
return pos;
break;
}
}
}
return pos;
}
文档说明:
相关文档
返回首页 | 关于本站 | | 友情链接 | 广告服务 | 意见建议 | 访客留言 | 本站论坛
Copyright© 2001-2006 ProgramBBS.com All Rights Reserved 版权所有©编程论坛
Email: 吉ICP备05009985号
感谢长春订餐网友情支持