We have a pile of cards consisting of 100 cards that are coloured on both sides. There is a finite number of colours (at most 26). In addition there are special cards called jokers. Jokers have a joker sign on both sides, which can
assume any of the possible colours. We consider here a one-player card game, in which the player is challenged to derive a given colour sequence from a given row of cards, following certain rules.
Before the actual beginning of the game a colour sequence S of length at most 100 (not containing a joker) is given. Furthermore a number of cards are chosen from the pile and are put in a row. The sides turned upwards form a row of colours. Now the aim for the player is to create the colour sequence S with the cards from the row in the following way. For each card in the row the player decides whether or not to turn it over. When the card is turned over, only the colour on the other side is visible. Jokers may be part of the row of cards.
These steps lead to the final sequence of colours formed by the visible side of the cards in the row. If the player has been able to turn the cards in such a way that the pre-given colour sequence S is contained (from left to right) in the final row of colours, the player wins. If not, he loses. In matching the pre-given colour sequence to the row, cards in the row may be skipped, as long as the relative order of the colours is preserved. A joker can assume any colour. For example, the colour sequence (red, blue, yellow) is contained in (green, joker, blue, red, yellow), and (blue, green, blue, green) is contained in (red, blue, joker, yellow, joker, blue, green, green).
Your job is to find out if the player can win, given the colour sequence S and the row of cards chosen from the pile. This means that the sequence of colours that are face up is known, and so are the colours on the other side of these cards.
Before the actual beginning of the game a colour sequence S of length at most 100 (not containing a joker) is given. Furthermore a number of cards are chosen from the pile and are put in a row. The sides turned upwards form a row of colours. Now the aim for the player is to create the colour sequence S with the cards from the row in the following way. For each card in the row the player decides whether or not to turn it over. When the card is turned over, only the colour on the other side is visible. Jokers may be part of the row of cards.
These steps lead to the final sequence of colours formed by the visible side of the cards in the row. If the player has been able to turn the cards in such a way that the pre-given colour sequence S is contained (from left to right) in the final row of colours, the player wins. If not, he loses. In matching the pre-given colour sequence to the row, cards in the row may be skipped, as long as the relative order of the colours is preserved. A joker can assume any colour. For example, the colour sequence (red, blue, yellow) is contained in (green, joker, blue, red, yellow), and (blue, green, blue, green) is contained in (red, blue, joker, yellow, joker, blue, green, green).
Your job is to find out if the player can win, given the colour sequence S and the row of cards chosen from the pile. This means that the sequence of colours that are face up is known, and so are the colours on the other side of these cards.
One line describing the colour sequence S. This line contains a string of m (with 1 ≤ m ≤ 100) characters from the set {'A', 'B', …, 'Z'}, denoting the colours. Different colours correspond to different characters. For example: "BGBG" denotes the sequence blue, green, blue, green.
Two lines, corresponding to the row of cards chosen from the pile. Each of these lines contains a string of k (1 ≤ k ≤ 100) characters from the set {'A', 'B', …, 'Z', '*'}. The character '*' denotes a joker, which can play the role of any of the possible colours.
The string in the first line corresponds to the row of colours on the visible side of the cards. The string in the second line corresponds to the row of colours on the hidden side of the cards.
So for the ith card in the row, the first line gives the colour of the side turned upwards and the second line shows the colour of the side face down. Obviously the strings on both lines have the same length. Furthermore, a '*' in one line (denoting a joker) always corresponds to a '*' in the other line at the corresponding position.
3 RBY B*RRB G*BRY BGBG RZ*Y*PGG AB*Y*BCB BAPC BUBCDAPVDAVVDLPF VLDCUSPGLSGPPVDD
win win lose
题意:一开始输入案例的个数,然后开始输入案例,案例包括模板串,还有匹配串,匹配串有两面,两面是可以翻转的,不同字母代表不同的颜色,“*”代表可以是任何颜色,要求从匹配串中找出模板串,若能“YES”否则“NO”
分析:我的算法中,sum这个数是很巧妙的,这里规定的是找到牌,没说顺序,意思就是可以单张牌比较也可以,只要有就行了,sum这个数只要符合条件,就++,而且sum用来a[]数组的定位,可以说是很完美。
#include <cstdio> #include <algorithm> #include <iostream> #include <queue> #include <string.h> #include <math.h> #include <cmath> using namespace std; int main() { char a[1001],b[1001],c[1001]; int t; cin>>t; while(t--) { int sum=0; int flag=0; scanf("%s%s%s",a,b,c); int len1=strlen(a); int len2=strlen(b); for(int i=0;i<len2;i++) { if(b[i]=='*'||c[i]=='*') { sum++; } else if(a[sum]==b[i]||a[sum]==c[i]) { sum++; } if(sum==len1) { flag=1; break; } } if(flag==1) printf("win\n"); else printf("lose\n"); } }