简体   繁体   中英

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM