Codeforce Round #208 Div.2 B
B. Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3word1<3word2<3 ... wordn<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
3
i
love
you
<3i<3love<23you<3
yes
7
i
am
not
main
in
the
family
<3i<>3am<3the<3<main<3in<3the<3><3family<3
no
Please note that Dima got a good old kick in the pants for the second sample from the statement.
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cmath> 7 #include <cstdio> 8 #include <cstring> 9 #include <iostream> 10 #include <algorithm> 11 using namespace std; 12 #define maxn 1000005 13 #define mod 1000000007 14 #define ll long long 15 #define INF 0x7fffffff 16 int n, m; 17 char s[maxn]; 18 char str[maxn]; 19 int main(){ 20 int cas = 1; 21 int t; 22 /*scanf("%d", &t); 23 while (t--){ 24 25 }*/ 26 while (~scanf("%d", &n)){ 27 m = 0; 28 s[0] = '<';s[1] = '3'; 29 for (int i = 0; i < n; i++){ 30 scanf("%s", s + m+2); 31 while (s[m] != '\0')m++; 32 s[m] = '<'; s[m + 1] = '3'; 33 } 34 int k=0; 35 scanf("%s", str); 36 m=max(strlen(str),strlen(s)); 37 for (int i = 0; i < m&&i+k<strlen(str);)if (str[i + k] != s[i])k++; else i++; 38 if (k==strlen(str)-strlen(s))printf("yes\n"); 39 else printf("no\n"); 40 } 41 return 0; 42 }
浙公网安备 33010602011771号