读书人

字符串包孕

发布时间: 2012-09-11 10:49:03 作者: rapoo

字符串包含
问题描述:判断B字符串中是否有字符与与A字符串中的的字符不同
如果不同的话,哪么输出false 如果都有 哪么输出true
例如:

ABCDEFG ABC
输出true
ABCDEF SAD
输出false 因为S不在A中

                           #include<iostream>#include<string>#include<cstring>using namespace std;bool Compare(string str1,string str2){   int i ,j;   bool bol = false;   int str1len=str1.length();   int str2len=str2.length();   for(i=0;i<str2len;i++)   {     for(j=0;j<str1len;j++)     {       if(str1[j]==str2[i])       {         bol = true;         break;       }       else       {        bol = false;        continue;       }     }     if(bol==true)     {       continue;     }     else     {       break;     }   }   if(bol)   return true;   else   return false;}int main(){ string str1,str2; while(cin>>str1>>str2) {  if(Compare(str1,str2))  cout<<"true"<<endl;  else  cout<<"false"<<endl; } return 0 ;}

读书人网 >编程

热点推荐