判断单词个数

#include<bits/stdc++.h>
using namespace std;
int main(){

    string w,s;
    while(1){
int t=0,t2=0,l,l2;    
    getline(cin,w);
    getline(cin,s);
    l=s.size();
    l2=w.size();
    for(int i=0;i<=l-l2;i++){
        int j;
        for(j=0;j<l-1;j++){
            if(toupper(s[i+j])!=toupper(w[j]))
                break;
            if(i>0&&s[i-1]!=' ')
                break;
        }
        if(j==l2&&s[i+j]==' '||j+i==l){
            t++;
            if(t==1)
                t2=i;
        }
    }
    if(t==0)
        cout<<"-1"<<endl;
    else
        cout<<t<<" "<<t2<<endl;
    }    return 0;
}

 

原文链接: https://www.cnblogs.com/lis92/p/12597620.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    判断单词个数

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/338882

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午11:49
下一篇 2023年3月1日 下午11:49

相关推荐