题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4545
这个题目没什么好解释的,在一个串中找另外一个串就行了,没什么难度
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define maxn 1500
char first[maxn],second[maxn],str[10];
int n,m;
map<char,set<char> > e;
bool find_ans(){//first变成second只要在first里面找到second就行了
int i=0,j=0,k;
while(second[i]){
k=1;
for(j;first[j];j++)
if(first[j]==second[i] || e[first[j]].find(second[i])!=e[first[j]].end()){
j++; k=0; break;
}
i++;
if(k) return false;
}
return true;
}
int main(){
int i,j,k=0,t;
scanf("%d",&t);
while(t--){
scanf("%s%s",second,first);
e.clear();
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%s%s",str,str+5);
e[str[0]].insert((str+5)[0]);
}
printf("Case #%d: ",++k);
if(find_ans()) printf("happy\n");
else printf("unhappy\n");
}
return 0;
}
本文介绍了一个简单的字符串匹配问题,通过在一个字符串中查找另一个字符串来解决实际问题。使用了C++语言进行实现,并利用了标准库中的map和set数据结构来辅助处理字符之间的转换关系。
361

被折叠的 条评论
为什么被折叠?



