#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;
}