就是一个一个的对应,最后的计算的时间是O(n*m)
//轮询方法O(n*m)
#include "iostream"
using namespace std;
int compareString(string longString, string shortString)
{
int longLength = longString.size();
int shortLength = shortString.size();
int i, j;
int count = 0;
for(i = 0; i < shortLength; i++)
{
for(j = 0; j < longLength; j++)
{
if(longString[j] == shortString[i])
{
count++;
break;
}
}
}
if(count == shortLength)
{
return 1;
}
else
return 0;
}
int main()
{
string str1 = "asdgsdg";
string str2 = "sgcd";
int judge = compareString(str1, str2);
if(judge == 1)
cout << "the long string contain the short string !";
else
cout <<" the long string don't contain the short string !";
cin.get();
cin.get();
return 0;
}