简体   繁体   English

如何检查C ++字符串中是否存在多个字母

[英]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.

相关问题 如何在 C++ 中增加字母? - How do I increment letters in c++? 如何检查 C++ 字符串是否为 int? - How do I check if a C++ string is an int? 如何检查网站是否包含C ++中的字符串? - How do I check if a website contains a string in c++? 我如何检查变量是否等于C ++中的多个事物? - How do I check if a variable is not equal to multiple things in C++? 如何在C ++字符串中分隔数字和字母? - How can I separate numbers and letters in a C++ String? 如何在C ++ 17中移动字符串的字母? - How can I shift the letters of a string in C++ 17? 如何在C ++中对数组中的字母排序? - How do I sort the letters in the array in C++? 如何从用户而不是示例中获取输入字符串,然后计算空格,标点符号,数字和字母。 C ++ - How do I take Input string from user instead of the example and then Count spaces, punctuation, digits, and letters. C++ C ++:如何使用堆栈检查字符串中是否存在相同数量的字母“ a”和“ b” - C++: How to check whether same number of letters 'a' and 'b' are present in a string using a stack 如何检查 C++ std::string 是否以某个字符串开头,并将子字符串转换为 int? - How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM