链接:

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;
}

最新文章

  1. python常见数据类型
  2. 2.Java异常学习
  3. ol新属性
  4. 关于GC垃圾回收的原理
  5. InputFormat,OutputFormat,InputSplit,RecordRead(一些常见面试题),使用yum安装64位Mysql
  6. python(6)
  7. Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
  8. 短信验证码js实现
  9. UVA 825 Walking on the Safe Side(记忆化搜索)
  10. 稳定婚姻问题和Gale-Shapley算法(转)
  11. 使用POI创建Excel文件下载
  12. Servlet实现文件上传(多文件)(三)
  13. bootstrap-datepicker的简单使用
  14. ACM Fibonacci数 计算
  15. 利用JS做网页特效——大图轮播
  16. Manacher’s Algorithm (神啊)
  17. JQ五星好评效果
  18. 12306登录爬虫 cookies版本
  19. [Linux性能调优] 磁盘I/O队列调度策略
  20. FlashFXP+FileZillaServer

热门文章

  1. python3实现自动化框架robotframework(最新)
  2. yum本地源和网络源的配置
  3. 线性模型-线性回归、Logistic分类
  4. ASM下添加磁盘
  5. spring boot-13.数据访问
  6. 小记---------FLUM的三种配置方式:spooldir、exec、hadoop sink
  7. frame的处理
  8. php之CGI、FastCGI、php-fpm运行原理
  9. layer.prompt绑定确认键
  10. 曹工说Spring Boot源码(5)-- 怎么从properties文件读取bean