吐泡泡题目链接:https://www.nowcoder.com/acm/contest/74/A

题目:

思路:
  这种题目当初卡了我很久,今天早训时遇到一个一样得题,一眼就想到用栈模拟,就又回来把这题补了。这题很简单,看代码基本上就能看懂,就不解释了。

代码实现如下:

 #include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;;
typedef pair<int, int> pii;
typedef unsigned long long ull; #define lson i<<1
#define rson i<<1|1
#define lowbit(x) x&(-x)
#define bug printf("*********\n");
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define FIN freopen("D://code//in.txt", "r", stdin);
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 1e6 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; char s[];
vector<char> v;
stack<char> p; int main() {
while(~scanf("%s", s)) {
v.clear();
while(!p.empty()) p.pop();
int len = strlen(s);
for(int i = ; i < len; i++) {
if(p.empty()) {
p.push(s[i]);
continue;
}
if(p.top() == 'o' && s[i] == 'o') {
p.pop();
if(p.empty() || p.top() != 'O') {
p.push('O');
} else {
p.pop();
}
} else if(s[i] == 'O' && !p.empty() && p.top() == 'O') {
p.pop();
continue;
} else {
p.push(s[i]);
}
}
while(!p.empty()) {
v.push_back(p.top());
p.pop();
}
reverse(v.begin(), v.end());
for(int i = ; i < v.size(); i++) {
printf("%c", v[i]);
}
printf("\n");
}
return ;
}

Plug-in题目链接:http://codeforces.com/problemset/problem/81/A

题目:

题意:

  给你一个串,如果相邻两个字母相同,则将这两个字母消掉,如果消掉几个字母之后又有相邻得两个字母继续消掉。

思路:

  同上。

代码实现如下:

  

 #include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;;
typedef pair<int, int> pii;
typedef unsigned long long ull; #define lson i<<1
#define rson i<<1|1
#define lowbit(x) x&(-x)
#define bug printf("*********\n");
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define FIN freopen("D://code//in.txt", "r", stdin);
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; char s[maxn];
vector<char> v;
stack<char> q; int main() {
scanf("%s", s);
q.push(s[]);
int len = strlen(s);
for(int i = ; i < len; i++) {
if(q.empty()) {q.push(s[i]);continue;}
if(s[i] == q.top()) {
q.pop();
} else {
q.push(s[i]);
}
}
while(!q.empty()) {
v.push_back(q.top());
q.pop();
}
reverse(v.begin(), v.end());
for(int i = ; i < v.size(); i++) {
printf("%c", v[i]);
}
printf("\n");
return ;
}

吐泡泡(2018年全国多校算法寒假训练营练习比赛(第二场)+栈模拟)+Plug-in(codeforces81A+栈模拟)的更多相关文章

  1. 2018年全国多校算法寒假训练营练习比赛(第四场)B:道路建设

    传送门:https://www.nowcoder.net/acm/contest/76/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 65536K,其他语言131072K 64b ...

  2. 2018年全国多校算法寒假训练营练习比赛(第四场)F:Call to your teacher

    传送门:https://www.nowcoder.net/acm/contest/76/F 题目描述 从实验室出来后,你忽然发现你居然把自己的电脑落在了实验室里,但是实验室的老师已经把大门锁上了.更糟 ...

  3. 牛客网-2018年全国多校算法寒假训练营练习比赛(第四场)-A

    解题思路:二分图的最大匹配,但这题是所有点都遍历一遍,所以答案/2: 代码: #include<iostream> #include<algorithm> #include&l ...

  4. 2018年全国多校算法寒假训练营练习比赛(第一场)闯关的lulu

    闯关的lulu 链接:https://www.nowcoder.com/acm/contest/67/J 来源:牛客网 题目描述 勇者lulu某天进入了一个高度10,000,000层的闯关塔,在塔里每 ...

  5. 2018年全国多校算法寒假训练营练习比赛(第一场)D N阶汉诺塔变形

    https://www.nowcoder.com/acm/contest/67/D 思路: 先手动模拟一下过程,以下是模拟过程,按顺序表示第几步需要移动的盘标号 1 1 2 1 1 2 1 1 3 1 ...

  6. 2018年全国多校算法寒假训练营练习比赛(第一场)E 恋与程序员

    https://www.nowcoder.com/acm/contest/67/E 思路: dfs 代码: #include<bits/stdc++.h> using namespace ...

  7. 2018年全国多校算法寒假训练营练习比赛(第一场)G 圆圈

    https://www.nowcoder.com/acm/contest/67/G 思路: 分形. 记录中间左边点的坐标,然后推出另外3个点的坐标,递归到最简单的情况. 代码: #include< ...

  8. 2018年全国多校算法寒假训练营练习比赛(第一场)C 六子冲

    https://www.nowcoder.com/acm/contest/67/C 思路: 模拟. 代码: #include<bits/stdc++.h> using namespace ...

  9. 2018年全国多校算法寒假训练营练习比赛(第二场)B - TaoTao要吃鸡

    链接:https://www.nowcoder.com/acm/contest/74/B来源:牛客网 题目描述 Taotao的电脑带不动绝地求生,所以taotao只能去玩pc版的荒野行动了, 和绝地求 ...

随机推荐

  1. 找"数学口袋精灵"bug

    团队成员的博客园地址: 刘森松:http://home.cnblogs.com/u/lssh/ 郭志豪:http://home.cnblogs.com/u/gzh13692021053/ 谭宇森:ht ...

  2. jquery截取手机号中间4位数,然后变为*

    $(function() { var phone = $('#phone').text(); var mphone = phone.substr(0, 3) + '****' + phone.subs ...

  3. caffe框架下目标检测——faster-rcnn实战篇操作

    原有模型 1.下载fasrer-rcnn源代码并安装 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 1) ...

  4. solr4.2增量索引之同步(修改,删除,新增)--转载

    原文地址:http://www.jiancool.com/article/12743229775/;jsessionid=14E9B3F1BB33399799884B5C8F15DDE1  solr增 ...

  5. 3.3 无连接运输:UDP

    3.3 无连接运输:UDP 简介: UDP提供不可靠的服务,它只做了运输层能做的最少工作,除了分解/复用以及少量的差错检测之外,几乎对IP没增加什么东西. 为什么应用开发人员宁愿再UDP之上构建应用, ...

  6. JDBC连接SQL Server

    下载jdbc驱动包 下载地址,我下载的是exe版本的,其实是格自解压包.下载完毕之后,双击运行,会解压在当前目录下. Microsoft SQL Server JDBC Driver 3.0\sqlj ...

  7. HDU-3974 Assign the task题解报告【dfs序+线段树】

    There is a company that has N employees(numbered from 1 to N),every employee in the company has a im ...

  8. 《Java程序设计》第7周学习总结 20165218 2017-2018-1

    20165218 2017-2018-1 <Java程序设计>第7周学习总结 教材学习内容总结 JDBC与MySQL数据库 数据库的功能:数据的存储.查询.修改.安全 MySQL:数据库: ...

  9. 函数式编程(1)-高阶变成(1)-map/reduce

    map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on ...

  10. Linux下C高手成长过程----经典书籍推荐

    http://www.cnblogs.com/shanzhizi/archive/2012/07/10/2585357.html