1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include<iostream> #include<cstring> using namespace std; string sentence,keyword; string cutsentence[1000000]; string cutfull[1000000]; int main(){ getline(cin,keyword); getline(cin,sentence); for(int i=0;i<keyword.size();i++){ if(keyword[i]>='A'&&keyword[i]<='Z'){ keyword[i]+=32; } } for(int i=0;i<sentence.size();i++){ if(sentence[i]>='A'&&sentence[i]<='Z'){ sentence[i]+=32; } } int blkflag=0; for(int i=0;i<sentence.size();i++){ if(sentence[i]==' '){ blkflag++; } } int cutnum=blkflag+1,cutflag=0; int count=0; for(int j=cutflag;j<=sentence.size();j++){ if(sentence[j]==' '||sentence[j]=='\0'){ for(int k=cutflag;k<j;k++){ cutsentence[count]+=sentence[k]; } count++; cutflag=j+1; } } int sameflag=0,samewordflag=0,firstflagnum=0; bool firstflag=false; for(int i=0;i<cutnum;i++){ if(cutsentence[i]==keyword){ samewordflag++; if(firstflag==false){ if(i>=1){ for(int o=0;o<i;o++){ firstflagnum+=cutsentence[o].size(); } firstflagnum+=i; }else if(i=0){ firstflagnum+=1; } firstflag=true; } } } if(samewordflag!=0){ cout<<samewordflag<<" "<<firstflagnum<<endl; }else if(samewordflag==0){ cout<<"-1"<<endl; } return 0; }
|