https://icpc.njust.edu.cn/Contest/749/A/

Description

小鱼喜欢吃糖果。他有两盒糖果,两盒糖果分别仅由小写字母组成的字符串s和字符串t构成。其中'a'到'z'表示具体的某种糖果类别。 他原本打算送给他喜欢的女生,但是要送给女孩子的话两盒糖果不能有差别(即字符串s和t完全相同)。所以,他决定偷吃几块,他吃糖果的策略是每次选出一盒糖果中两个连续的同种类别的糖果,然后吃掉其中一块。该策略可以使用多次。 例如一盒糖果是'rrrjj',他可以把这盒糖果变成'rrjj'或者'rrrj'。现在你要告诉小鱼,经过他多次偷吃糖果之后,两盒糖果能否送给他喜欢的女孩子。如果可以输出'Yes',如果不行输出'No'。

Input

第一行一个T,表示T组测试数据。每组测试数据格式如下。 第一行表示字符串s,第二行表示字符串t。 1 ≤ T ≤ 100 Each character of s, t will be between 'a' and 'z'. 1 ≤ length of string s ≤ 1000 1 ≤ length of string t ≤ 1000

Output

对于每组测试数据,输出Yes,或者No。

Sample Input

2
rrrjj
rrrj
rj
jr

Sample Output

Yes
No

Hint

题目中的第一个样例:第一盒糖果:rrrjj -> rrjj -> rjj -> rj第二盒糖果:rrrj -> rrj -> rj

题目大意很直白 突然想到有unique实现 但是对unique的理解不太太深 导致CE

 #include<cstdio>
#include<map>
//#include<bits/stdc++.h>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<climits>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
string a,b;
cin>>a>>b;
a.erase(unique(a.begin(), a.end()), a.end());
b.erase(unique(b.begin(), b.end()), b.end());
if(a==b)puts("Yes");
else puts("No");
}
return ;
}

AC代码

需要注意的是unique并不是真正意义上的消去重复 只能移动相邻相同的到尾部 并返回尾部地址

如果只要消去后的

我们可以使用erase 或者尾部地址-vector数组首地址得到长度

如果想把数组中所有重复的消去 则需要sort 然后相同的都变为相邻的 就可以实现啦

unique真的是个神奇的东西

模拟水题之unique两行AC的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  3. 模拟水题,查看二维数组是否有一列都为1(POJ2864)

    题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...

  4. UVA 10714 Ants 蚂蚁 贪心+模拟 水题

    题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...

  5. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  6. HDU4287-STL模拟水题

    一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...

  7. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  8. Reversing Encryption(模拟水题)

    A string ss of length nn can be encrypted(加密) by the following algorithm: iterate(迭代) over all divis ...

  9. Mishka and Contest(模拟水题)

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...

随机推荐

  1. UVa 11520 Fill the Square (水题,暴力)

    题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...

  2. E20181120-hm

    checkerboard n. 西洋跳棋盘; checker n. 方格图案;

  3. IOS11 - UINavigationItem大标题,搜索栏实现

    1.新建模型 class Contact: NSObject { var name : String? var mobile : String?{ didSet{ { mobileString = m ...

  4. iOS代码封装成.a文件(封装SDK)

    在众多开源的大神的博客里经整理如下:(已测试ok) 一.描述一下 Build ActiveArchitecture Only设置成YES: Architectures按Xcode默认配置,arm64向 ...

  5. caller和callee的解析与使用-型参与实参的访问

    caller:是一个函数引用(当前执行函数”被调用的地方”{即这个”被调用的地方”函数引用},如果这个”被调用的地方”是window,则返回[null]),是函数名的属性: var a = funct ...

  6. 洛谷P4570 [BJWC2011]元素(线性基)

    传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 考虑贪心 将所有的矿石按价值从大到小排序 如果一块矿石不会和之前的编号异或为0就加入 这个只要判一下它能不能加进线性基里就可以了 据说这个贪心的证明 ...

  7. ISO 8 自适应cell

    原文网址: http://www.cocoachina.com/ios/20141218/10687.html 在使用 table view 的时侯经常会遇到这样的需求:table view 的 ce ...

  8. Validation(3)--全局参数异常校验捕获及返回XML解决

    @RestControllerAdvice原创直接上代码,后面再说怎么用1.这个是一个Form,用来接收参数的,一个简单的NotEmpty注解校验,merchantName这个参数是必传的: pack ...

  9. 51nod 1562 玻璃切割 (set)

    #include<stdio.h> #include<iostream> #include<set> using namespace std; typedef lo ...

  10. 大数(string 之间的快速幂)

    //字符串的乘法 string multi(string a, string b){ ], len = a.length() + b.length(); memset(arr, , sizeof ar ...