B – Email from Polycarp

Methodius received an email from his friend Polycarp. However, Polycarp’s keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).

For example, as a result of typing the word “hello”, the following words could be printed: “hello”, “hhhhello”, “hheeeellllooo”, but the following could not be printed: “hell”, “helo”, “hhllllooo”.< /span>

Note, that when you press a key, the corresponding symbol must appe ar (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.

For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.< /p>

You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp’s keyboard.

Input

< span style="font-size: 16px;">The first line of the input contains one integer n

“>n

(1n105

“>1n105

“>1n105 ) — the number of pairs to check. Further input contains n

“>n

descriptions of pairs.

The first line of each description con tains a single non-empty word s

“>s< /p> 1n10 5

“> 1n10 5

“>n

“> consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t

“>< span id="MathJax-Span-19" class="math" style="width: 0.426em; display: inline-block;">t consisting of lowercase Latin letters. The lengths of both strings are not great er than 106

“>106< /span>

.

It is guaranteed that the total length of all words s

“>s

1n105

“> 1n 105

“>n

“>t

“>106

“> in the input is not greater than 106

“>106. Also, it is guaranteed that the total length of all words t

“>< span style="display: inline-block; position: relative; width: 0.37em; height: 0px;">t in the input is not greater than 106

“>106< /span>

.

1n105

“>1n 105

“>n

“>t

“>106< /msup>

“>106

“>t

“>106

“> Output

Output n

“>n

1n105

“> 1n105

“>n

“>t“>< mn>106

“>106

“>t

“> 106

“> lines. In the i

“>i-th line for the i

“>i-th pair of words s

“>s span> and t

“>t print YES if the word t

“>t could be printed by typing the word s

“>s

. Otherwise, print NO. span>

1< /mn>n105

“>1n10< /mn>5

“>n

“>t

“>106“>< mn>106

“>t“>106

“>i

“>i

“>s

“>t

“>t

“>s

“> Examples< /span>

Input

< pre>4

hello

hello

hello

helloo

hello

hlllloo

hello

helo

Output
YES

YES
NO
NO

Input
5

aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

Output
NO

NO
YES
NO
NO

The meaning of the question is: the keyboard is broken (multiple identical characters appear at a time), the first line is the correct string, to determine whether the second line of characters is the first line of string, press on the broken keyboard from.
Idea: Separate the movement of the first line of strings.

#include  #include  #include #include< /span><string> #include #include #include  # include <string.h> #include  #include <set>

using namespace std; int main() {int n; while(cin >>< span style="color: #000000;"> n) {
for(int< /span> i = 0; i ) {string a, b; cin >> a >> b; int len2 = b.length(); int pow = 0; int flag = 1, ans = 0; for(int i = 0; i ) {if(b[ i] == a[pow]) {pow++;} else {if(i > 0 && b[i] == a[pow-1]) continue; else {flag = 0; break;}}} if(pow != a.length()) {flag = 0;} < span style="color: #0000ff;">if
(flag == 0) cout << "NO" << endl; else cout << "YES" << endl;}} return 0; }

Input

The first line of the input contains one integer n

“> n

(1n 105

“>1n105

“>1n105 span>) — the number of pairs to check. Further input contains n

“>n< /span>

descriptions of pairs .

The first line of each description contains a single non-empty word s< /math>“>s

1n105

“> 1n105

“>n

“> consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t

“>t consisting of lowercase Latin letters. The lengths of both strings are not greater than 106

“>106

.

It is guaranteed that the total length of all words s

“>s

1n105

“> 1n105

“>n

“>t

“>106

“> in the input is not greater than 106

“>106. Also, it is guaranteed that the total length of all words t

“>t in the input is not greater than 106

“>106

.

1n105

“>1n105

“>n

“>t

“>106

“>106“>t

“>106

“> Output

Output n

“>n

1n105

“>1n105

“>n

“>t

“>106

“> 106

“>t

“>106

“> lines. In the i

“>i-th line for the i

“>i-th pair of words s

“>s and t

“>t print YES if the word t

“>t could be printed by typing the word s

“>s< /span>

. Otherwise, print NO.

1n105

“>1n105

“>n

“>t

“>106

“>106

“>t

“>106

“>i

“>i

“>s

“>t

“>t

“>s

“> Examples

Input
4

hello
hello
hello
helloo
hello
hlllloo
hello
helo

Output
YES

YES
NO
NO

Input
5

aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

Output
NO

NO
YES
NO
NO

题意就是:键盘坏了(按一次出现多个相同字符),第一行是正确字符串 , 判断第二行字符是否是第一行字符串在坏的键盘上按出来的。
思路:将第一行字符串的移动独立出来。

#include  #include  #include #include<string> #include #include #include  #include <string.h> #include  #include <set>

using namespace std; int main() { int n ; while(cin >> n) { for(int i = 0 ; i < n ; i++) { string a , b ; cin >> a >> b ; int len2 = b.length() ; int pow = 0 ; int flag = 1 , ans = 0; for(int i = 0 ; i < len2 ; i++) { if(b[i] == a[pow]) { pow++ ; } else { if(i > 0 && b[i] == a[pow - 1]) continue ; else { flag = 0 ; break ; } } } if(pow != a.length()) { flag = 0 ; } if(flag == 0) cout << "NO" << endl ; else cout << "YES" << endl ; } } return 0; }

Input
4

hello
hello
hello
helloo
hello
hlllloo
hello
helo

Output
YES

YES
NO
NO

Input
5

aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

Output
NO

NO
YES
NO
NO

题意就是:键盘坏了(按一次出现多个相同字符),第一行是正确字符串 , 判断第二行字符是否是第一行字符串在坏的键盘上按出来的。
思路:将第一行字符串的移动独立出来。

#include  #include  #include #include<string> #include #include #include  #include <string.h> #include  #include <set>

using namespace std; int main() { int n ; while(cin >> n) { for(int i = 0 ; i < n ; i++) { string a , b ; cin >> a >> b ; int len2 = b.length() ; int pow = 0 ; int flag = 1 , ans = 0; for(int i = 0 ; i < len2 ; i++) { if(b[i] == a[pow]) { pow++ ; } else { if(i > 0 && b[i] == a[pow - 1]) continue ; else { flag = 0 ; break ; } } } if(pow != a.length()) { flag = 0 ; } if(flag == 0) cout << "NO" << endl ; else cout << "YES" << endl ; } } return 0; }

Input
4

hello
hello
hello
helloo
hello
hlllloo
hello
helo

Input

Output
YES

YES
NO
NO

Output

Input
5

aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

Input

Output
NO

NO
YES
NO
NO

题意就是:键盘坏了(按一次出现多个相同字符),第一行是正确字符串 , 判断第二行字符是否是第一行字符串在坏的键盘上按出来的。
思路:将第一行字符串的移动独立出来。

#include  #include  #include #include<string> #include #include #include  #include <string.h> #include  #include <set>

using namespace std; int main() { int n ; while(cin >> n) { for(int i = 0 ; i < n ; i++) { string a , b ; cin >> a >> b ; int len2 = b.length() ; int pow = 0 ; int flag = 1 , ans = 0; for(int i = 0 ; i < len2 ; i++) { if(b[i] == a[pow]) { pow++ ; } else { if(i > 0 && b[i] == a[pow - 1]) continue ; else { flag = 0 ; break ; } } } if(pow != a.length()) { flag = 0 ; } if(flag == 0) cout << "NO" << endl ; else cout << "YES" << endl ; } } return 0; }

Output

#include  #include  #include #include<string> #include #include #include  #include <string.h> #include  #include <set>

using namespace std; int main() { int n ; while(cin >> n) { for(int i = 0 ; i < n ; i++) { string a , b ; cin >> a >> b ; int len2 = b.length() ; int pow = 0 ; int flag = 1 , ans = 0; for(int i = 0 ; i < len2 ; i++) { if(b[i] == a[pow]) { pow++ ; } else { if(i > 0 && b[i] == a[pow - 1]) continue ; else { flag = 0 ; break ; } } } if(pow != a.length()) { flag = 0 ; } if(flag == 0) cout << "NO" << endl ; else cout << "YES" << endl ; } } return 0; }

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3952 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.