为什么必须要用getline?大佬求助
查看原帖
为什么必须要用getline?大佬求助
1271081
hnpop8楼主2024/9/16 10:33

代码部分

#include<bits/stdc++.h>
using namespace std;
int wz=-1,sl=0;
bool p=true;
string a,b;
int main(){
   getline(cin,a);
   getline(cin,b);
   if(a[a.length()-1]!=' ')a+=' ';
   transform(a.begin(),a.end(),a.begin(),::toupper);
   transform(b.begin(),b.end(),b.begin(),::toupper);
   b+=" ";
   for(int i=0;i<=b.length();i++){
       for(int j=0;j<a.length();j++){
           if(b[j+i]!=a[j]) p=false;
       }
       if(p==true){
           if(b[i-1]==' '||i==0){
               sl++;
               if(wz==-1) wz=i;
           }
       }
       p=true;
   }
   if(wz==-1) cout<<wz;
   else cout<<sl<<" "<<wz;
   return 0;
}
2024/9/16 10:33
加载中...