松哥的困惑 STL

在这里插入图片描述
思路:直接先找字符串中有没有三个大写的字符,三个大写的字符就满足了名字是三个字,然后再用string类中的find方法找子串,如果存在就返回第一个找到的子串的位置,否则返回-1.

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    
    
    while(cin>>n){
    
    
        while(n--){
    
    
            string s; cin>>s;
            int cnt = 0;
            for(int i=0;i<s.length();i++){
    
    
                if(s[i]>='A'&&s[i]<='Z')
                    cnt++;
            }
            if(cnt == 3){
    
    
                if(s.find("Ting")!=-1&&s.find("Li")!=-1){
    
    
                    cout<<s<<endl;
                }
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43811879/article/details/109604918
STL