zoukankan      html  css  js  c++  java
  • Codeforces Round #568 (Div. 2)B

    B. Email from Polycarp

    题目链接:http://codeforces.com/contest/1185/problem/B

    题目:

    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".

    Note, that when you press a key, the corresponding symbol must appear (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.

    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

    The first line of the input contains one integer n (1≤n≤105) — the number of pairs to check. Further input contains n descriptions of pairs.

    The first line of each description contains a single non-empty word s
    consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 106

    .

    It is guaranteed that the total length of all words s
    in the input is not greater than 106. Also, it is guaranteed that the total length of all words t in the input is not greater than 106

    .
    Output

    Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
    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<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const int maxn=1e6+7;
    struct node{
        char str;
        int num;
    }node[maxn],node1[maxn];
    int main()
    {
        int n;
       scanf("%d",&n);
            char str[maxn],str1[maxn];
            while(n--)
            {
                scanf("%s%s",str,str1);
                int num=strlen(str);
                int num1=strlen(str1);
                int book=0,book1=0;
                for(int i=0;i<max(num,num1);i++)
                {
                    node[i].num=0;
                    node1[i].num=0;
                }
                node[0].str=str[0];
                node1[0].str=str1[0];
                node[0].num=1;
                node1[0].num=1;
                for(int i=1;i<num;i++)
                {
                    if(str[i]==str[i-1])
                    {
                        node[book].num++;
                        node[book].str = str[i];
                    }
                    else
                    {
                        book++;
                        node[book].num++;
                        node[book].str=str[i];
                    }
    
                }
                for(int i=1;i<num1;i++)
                {
                    if(str1[i]==str1[i-1])
                    {
                        node1[book1].num++;
                        node1[book1].str = str1[i];
                    }
                    else
                    {
                        book1++;
                        node1[book1].num++;
                        node1[book1].str=str1[i];
                    }
                }
                int sum=unique(str,str+num)-str;
                int sum1=unique(str1,str1+num1)-str1;
                if(num>num1)
                    puts("NO");
                else if(sum!=sum1)
                    puts("NO");
                else {
    
                    bool flag = true;
                    for (int i = 0; i < sum; i++) {
                        if (node[i].str != node1[i].str || node[i].num > node1[i].num) {
                            flag = false;
                            break;
                        }
    
                    }
                    if (flag)
                        puts("YES");
                    else
                        puts("NO");
                }
    
            }
    
    
        return 0;
    }
    /*
    4
    polycarp
    poolycarpp
    
     */
  • 相关阅读:
    【笔记】关于全栈开发、技术发展方向,软件开发模式的思考
    转 mysql 自动安装部署
    转shell不能执行su 后的脚本
    11.2 rman 备份 放在DG 库上跑,可能遇到的问题。
    highchart 学习
    每周定时备份linux 文件内容 到 远端主机
    转 javascript 本地时间 和utc 节点 和 时间戳转换 的
    转 钢铁侠的云之舞~多租户,Docker,虚拟机 , 你怎么选?
    转 perl 的调试
    转 pt-query-digest 使用实例
  • 原文地址:https://www.cnblogs.com/Vampire6/p/11059719.html
Copyright © 2011-2022 走看看