吐泡泡题目链接: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. 1029 C语言文法定义

    program à external_declaration | program external_declaration <源程序> ->  <外部声明> |  < ...

  2. maven 实践 :管理依赖

    有人认为Maven是一个依赖管理工具,当然这种想法是错误的(确切的说Maven是一个项目管理工具,贯穿了整个项目生命周期,编译,测试,打包,发布...),但Maven给人造成这种错误的印象也是有原因的 ...

  3. html超链接返回上一页面

    超链实现返回刚刚访问的网页: <a href="#" onclick="javascript:history.back(-1);"></a&g ...

  4. linux php 访问sql server设置

    1.安装freeTDS wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz 1.1.进入到你下载的目录然后解压.tar - ...

  5. Filter2D卷积运算

    图像处理中的卷积运算一般都用来平滑图像.尖锐图像求边缘等等.主要看你选择什么样的核函数了.现在核函数很多,比如高斯平滑核函数,sobel核函数,canny核函数等等.这里举一个sobel核函数的例子来 ...

  6. ssh & sftp & MacOS

    ssh & sftp & MacOS https://www.technoduet.com/a-simple-way-to-connect-to-remote-ftp-sever-on ...

  7. 【Python】内置函数

    一.内置函数表格 详细信息 二.内置函数详情 2.1 abs(x) 返回绝对值 1 2 >>> abs(-5) 5 2.2 all(iterable) 如果这个可迭代的元素都为真,就 ...

  8. bootstrap-datapicker 时间约束

    <div class="input-group date date-picker" id="StartTime"> <input type=& ...

  9. VLC for Android 编译过程

    首先,给一个VLC的官网链接:VLC-AndroidCompile 上面有编译所需要安装的插件,环境变量的配置等等信息:虽然是英语,但也挺好理解,这里就不再详述:此文主要记录我在编译的过程中遇到的一些 ...

  10. 关于kali linux系统的简单工具

    Linux系统中关于几个重要目录的原英文解释: /etc/: Contains configuration files of the installed tools /opt/: Contains M ...