[英]How do I check if multiple letters exist in a string in C++
例如,在字符串“ RADIOACTIVE”中,如何检查字符串中是否所有“ R”,“ E”,“ O”和“ A”都出现。我应该如何编写男女同校
Find out which letters are available in your main string. 找出您的主字符串中可用的字母。 Then check each letter you want whether they are available or not. 然后检查您想要的每个字母是否可用。
string S = "RADIOACTIVE";
bool avail[26]={false};
for(int i=0; i<S.length(); i++)
avail[S[i]] = true;
string s = "REOA";
bool All = true;
for(int i=0; i<s.length(); i++)
if(!avail[s[i]])
{
All = false;
break;
}
if(All)
cout << "All letters found" << endl;
else
cout << "All letters not found" << endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.