本文主要是介绍HDU 4545 魔法串(water!),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接: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;
}
这篇关于HDU 4545 魔法串(water!)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!