D - Colour sequence
来源:互联网 发布:网络发射器和接收器 编辑:程序博客网 时间:2024/06/06 11:46
Description
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.
Input
The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:
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.
Output
For every test case in the input file, the output should contain one line. This line contains "win" if the colour sequence S can be achieved by the player by turning the right cards upside down, and "lose" if this is not the case.
Sample Input
3
RBY
B*RRB
G*BRY
BGBG
RZ*Y*PGG
AB*Y*BCB
BAPC
BUBCDAPVDAVVDLPF
VLDCUSPGLSGPPVDD
Sample Output
win
win
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.
Input
The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:
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.
Output
For every test case in the input file, the output should contain one line. This line contains "win" if the colour sequence S can be achieved by the player by turning the right cards upside down, and "lose" if this is not the case.
Sample Input
3
RBY
B*RRB
G*BRY
BGBG
RZ*Y*PGG
AB*Y*BCB
BAPC
BUBCDAPVDAVVDLPF
VLDCUSPGLSGPPVDD
Sample Output
win
win
lose
题意: 输入三串 字符, 第二行表示牌的正面, 第三行表示牌的反面,有*表示能形成任意一个牌面,是否能形成第一行
#include<iostream>#include<cmath>#include<cstring>#include<algorithm>using namespace std;int main (){ int testcase; int i; string zheng,fan,charset; cin>>testcase; while(testcase--) { int pos1=0,pos2=0; cin>>charset>>zheng>>fan; while(pos2<=zheng.size()) { if(zheng[pos2]=='*'||fan[pos2]=='*') { pos1++; pos2++; } else if(charset[pos1]==zheng[pos2] || charset[pos1]==fan[pos2]) { pos1++; pos2++; } else { pos2++; } if(pos1==charset.size()) { cout<<"win"<<endl; break; } } if(pos2>zheng.size()) cout<<"lose"<<endl; } return 0;}
0 0
- D - Colour sequence
- hdu1683--Colour sequence
- hdu 1683 Colour sequence
- POJ 3458 Colour Sequence
- Colour sequence HDU
- POJ 3458 Colour Sequence G++
- hdu 1683 Colour sequence(简单模拟)
- POJ 3458 Colour Sequence(简单题)
- hdu 1683 Colour sequence 有多种解法的题目
- POJ 3458 && HDU 1683 Colour Sequence(水~)
- 【CODEFORCES】 D. Increase Sequence
- D - BestCoder Sequence
- [CF407E]k-d-sequence
- bzoj4527: K-D-Sequence
- colour name
- Codeforces 466 D. Increase Sequence
- 【codeforces 602D】Lipshitz Sequence
- D. Least Cost Bracket Sequence
- dbms_stats
- 算是开通博客的通告吧
- VS调试问题,程序无法正常启动 (使用openFlight_API中遇到的问题)
- Android获取系统语言(区分简体中文和繁体中文) .
- 注册欧盟商标
- D - Colour sequence
- java异常处理机制
- STM32 硬件IIC操作
- Decode Ways
- 设计模式系列之代理
- Vs2010中删除空行
- 单例运用的范围
- Centos下 ffmpeg 和opencv一起配合处理视频
- 硬盘分区数据丢失怎么恢复