top1编程
← 返回题目
题解

单词

1 条题解

  • 0
    @ 2026-7-28 22:44:53
    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        string s,w="",t;
        int c=0,c2=0;
        bool f=false;
        getline(cin,s);
        cin>>t;
        for(int i=0;i<s.size()-1;i++){
            if(s[i]!=' '){
                c2++;
                w=w+s[i];
                if(s[i+1]==' '||s[i+1]=='.'){
                    c++;
                    if(w==t){
                        cout<<c;
                        f=true;
                        break;
                    }
                    w="";
                }
            }
        }
        if(f==false){
            cout<<c2;
        }
     return 0;
    }
    
    • 1