吐泡泡题目链接: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. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

  2. Building microservices with ASP.NET Core (without MVC)(转)

    There are several reasons why it makes sense to build super-lightweight HTTP services (or, despite a ...

  3. sublime text3 php开发必要的插件

    一.安装Sublime Text 3 官网 http://www.sublimetext.com/3 一定要选择ST3,而不是ST2,3比2好用,真的,后面你就知道了. 选择对应的版本安装.完事后,要 ...

  4. java finally 与return

    finally之外的语句块有return,finally语句块没有return:该语句块的返回值被固定下来,等fianlly执行完后返回给调用者 finally语句块与其他语句块同时有return:返 ...

  5. 【bzoj2560】串珠子 状压dp+容斥原理

    题目描述 有 $n$ 个点,点 $i$ 和点 $j$ 之间可以连 $0\sim c_{i,j}$ 条无向边.求连成一张无向连通图的方案数模 $10^9+7$ .两个方案不同,当且仅当:存在点对 $(i ...

  6. 【Mybatis】简单的mybatis增删改查模板

    简单的mybatis增删改查模板: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE map ...

  7. BZOJ3594 SCOI2014方伯伯的玉米田(动态规划+树状数组)

    可以发现每次都对后缀+1是不会劣的.考虑dp:设f[i][j]为前i个数一共+1了j次时包含第i个数的LIS长度.则f[i][j]=max(f[i][j-1],f[k][l]+1) (k<i,l ...

  8. 洛谷 P5078 Tweetuzki 爱军训

    题目连接 很明显,1e6的范围,要么nlgn要么O(n) nlgn的话可能会想到借助一些数据结构,我并没有想到这种做法 对于这种题,O(n)的做法要么是线性递推,要么就应该是贪心了 考虑这道题我们怎么 ...

  9. [NOI2008]糖果雨

    bzoj1062[Noi2008]糖果雨 首先给出的颜色没有用. 估计要用数据结构.而线段难以维护. 考虑把线段变成点 T是单增的. 所以询问的时候,存在的线段都可能贡献答案. 那些线段的位置如果可以 ...

  10. 【数论】数论进阶-Preknowledge

    数论进阶-Preknowledge 参考资料:洛谷网校2018夏季省选基础班SX-3数论进阶课程及课件 一.整除与取整除法 1.1 定义 1.整除 \(\forall~x,y~\in~Z^+,\) 若 ...