Codeforces Round #568 (Div. 2) B. Email from Polycarp

链接:

https://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.

思路:

将每个字符串对应的字母和相连次数存下来,比较一下即可。

代码:

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
vector<pair<char, int> > inp;
vector<pair<char, int> > out;
string a, b;
 
bool Solve()
{
    if (inp.size() != out.size())
        return false;
    for (int i = 0;i < inp.size();i++)
    {
        if (inp[i].first != out[i].first)
            return false;
        if (inp[i].second > out[i].second)
            return false;
    }
    return true;
}
 
int main()
{
    cin >> t;
    while (t--)
    {
        inp.clear(), out.clear();
        cin >> a >> b;
        int tmp = 0;
        for (int i = 0;i <= a.length();i++)
        {
            if (i == a.length() || (i > 0 && a[i] != a[i-1]))
                inp.emplace_back(a[i-1], tmp), tmp = 0;
            tmp++;
        }
        tmp = 0;
        for (int i = 0;i <= b.length();i++)
        {
            if (i == b.length() || (i > 0 && b[i] != b[i-1]))
                out.emplace_back(b[i-1], tmp), tmp = 0;
            tmp++;
        }
//        for (auto pa:inp)
//            cout << pa.first << ' ' << pa.second << endl;
        if (Solve())
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
 
    return 0;
}

转载于:https://www.cnblogs.com/YDDDD/p/11155347.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值