模拟水题之unique两行AC
https://icpc.njust.edu.cn/Contest/749/A/
Description
Input
Output
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的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- 模拟水题,查看二维数组是否有一列都为1(POJ2864)
题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- HDU4287-STL模拟水题
一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- Reversing Encryption(模拟水题)
A string ss of length nn can be encrypted(加密) by the following algorithm: iterate(迭代) over all divis ...
- Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
随机推荐
- HrrpClient使用
使用HttpClient获取网页内容的过程 1.创建一个CloseableHttpClient类的实例: 2.使用这个实例执行HTTP请求,得到一个HttpResponse的实例: 3.最后,通过Ht ...
- python模块datetime
1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.now() now.strftime('%Y-%m-% ...
- CCF 201512-3 画图 (DFS搜索+模拟)
问题描述 用 ASCII 字符来画图是一件有趣的事情,并形成了一门被称为 ASCII Art 的艺术.例如,下图是用 ASCII 字符画出来的 CSPRO 字样. ..____.____..____. ...
- 51nod 1416【DFS】
思路: 暴力整个图,以这个为起点,然后看一下有没有找到一条路是会指向自己且元素个数>=4: #include <bits/stdc++.h> using namespace std; ...
- caller和callee的解析与使用-型参与实参的访问
caller:是一个函数引用(当前执行函数”被调用的地方”{即这个”被调用的地方”函数引用},如果这个”被调用的地方”是window,则返回[null]),是函数名的属性: var a = funct ...
- Python decorate 函数
1. decorate 函数需要在 "@wrap" 之前定义, 否则会报错
- linux mysql乱码问题
mysql,发现都是乱码,一堆问号,如下图: 查看mysql编码 需要修改mysql编码,打开/etc/my.cnf 文件 在下边添加如下行 [client] default_character_se ...
- python文件实现增删改查操作
# coding = utf-8 import os import json import re ''' 本程序旨在将练习基础知识部分,包括: 列表,元组,字典,文件,函数,字符串等知识 实现的功能: ...
- 网络请求方法(SDK封装可以替换afn)
//个人觉得 sdk开发时候 最好不要用第三方 最好可以用最原始的方法 替换 此处仅做sdk封装使用 留存+(void)GET:(NSString *)urlStr params:(NSDiction ...
- $.ajax()与vue结合获取数据并渲染
html: <div id="app1"> <ul> <li v-for="item in datas"> <div ...