码迷,mamicode.com
首页 > 其他好文 > 详细

蒟蒻继续打新手村。。。

时间:2019-10-17 01:28:00      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:return   匹配   clu   com   include   span   namespace   输入   word   

技术图片技术图片

#include<iostream> #include<cstring> #include<cstdio> using namespace std; string sent,word; int lens,lenw,t,pos; int main() { getline(cin,word); getline(cin,sent); //!!!!!!!字符串含有空格输入,不可以用cin,否则to me只能读到to lenw=word.size(); // 不能用s1.lenth()。。。 lens=sent.size(); for(int i=0;i<lenw;i++) word[i]=toupper(word[i]); //转成大写 for(int i=0;i<lens;i++) sent[i]=toupper(sent[i]); t=0; for(int i=0;i<=lens-lenw;i++) { int j; for(j=0;j<lenw;++j) { if(sent[j+i]!=word[j]) break; if(i>0&&sent[i-1]!= ) break; //前一个不是空格则终止 } if(j==lenw&&(sent[j+i]== ||j+i==lens)) //单词长度匹配,后面是空格或者句末 { t++; //目的:为了输出单词第一次出现的位置 if(t==1) pos=i;          // 学到了。。。 } } if(t==0)cout<<-1; else cout<<t<<" "<<pos; return 0; }

 

蒟蒻继续打新手村。。。

标签:return   匹配   clu   com   include   span   namespace   输入   word   

原文地址:https://www.cnblogs.com/poo7/p/11689394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!