您的位置:首页 > 其它

CCF 201409-3 字符串匹配

2016-12-16 15:03 197 查看
//@start time:
//@finish time:
/*@此处注意:
ascii码之间大小写的关系,不熟练就输出来看看
*/
/* 测试数据
Hello
1
5
HelloWorld
HiHiHelloHiHi
GrepIsAGreatTool
HELLO
HELLOisNOTHello

Hello
0
5
HelloWorld
HiHiHelloHiHi
GrepIsAGreatTool
HELLO
HELLOisNOTHello

*/
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;

int main(){
string checker;
cin>>checker;
int permit;
cin>>permit;
int numofline;
cin>>numofline;
char tocheck[101][101];
if(permit){ //大小写敏感,要判断大小写
for(int i=0;i<numofline;i++){
cin>>tocheck[i];
if(strstr(tocheck[i],checker.c_str())!=NULL)
cout<<tocheck[i]<<endl;
}

}

else{//不敏感,就把所有的都换成小写的,然后进行判断
for(int i=0;i<numofline;i++){
cin>>tocheck[i];
char temp[101];
char tmpcker[101];
strcpy(temp,tocheck[i]);
for(int j=0;temp[j]!='\0';j++){
if((temp[j]>='A')&&(temp[j]<='Z')){
temp[j]+=('a'-'A');
}
}
//	cout<<"temp:"<<temp<<endl;
for(int j=0;j<checker.size();j++){
if((checker[j]>='A')&&(checker[j]<='Z')) tmpcker[j]=checker[j]+('a'-'A');
else tmpcker[j]=checker[j];

}
//		cout<<"tmpcker:"<<tmpcker<<endl;
if(strstr(temp,tmpcker)!=NULL)
cout<<tocheck[i]<<endl;
}

}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: