Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 2) A. Interview wi
来源:互联网 发布:淘宝网客户端 编辑:程序博客网 时间:2024/05/20 18:45
题意
给你一个字符串
里面有ogo ogogo ogogogo这样的要变成*
例如
7
aogogob
a***b
13
ogogmgogogogo
gmg
9
ogoogoogo
然后输出
如果有ogogo 也只输出 *
算法
这个其实想清楚了,就是一个区间覆盖问题,或者说更简单,我也不清楚
首先把区间找出来 就是有ogo的区间
不过好像现在想想 不可能会有重合的区间 更简单
不过我就是拿区间覆盖来做的
区间覆盖就是要排序 结束长的先放
所以首先就把这个区间找出来,然后排序,用pair来存 少写比较函数
然后就枚举每个字符的位置 如果在区间 就输出* 同时更新区间 否则就输出原来的字符
#define LOG(x) cout << #x << " = " << (x) << endl#define PRINTLN(x) cout << (x) << endl#define MEM(x, y) memset((x), (y), sizeof((x)))#include <bits/stdc++.h>using namespace std;const double PI = 2*acos(0);typedef long long ll;typedef complex<double> Complex;typedef pair<int, int> P;int nextInt(){ int x; scanf("%d", &x); return x;}ll nextLL(){ ll x; scanf("%lld", &x); return x;}//TEMPLATE//MAINint n;const int MAXN = 1000;char a[MAXN];vector<P> ps;void solve(){ for (int i = 0; i < n; i++) { scanf("%c", &a[i]); } ps.clear(); for (int i = 0; i < n; i++) { if (a[i] != 'o') continue; int r = 0; for (int j = 1; i + j + 1 < n; j += 2) { if (i + j + 1 >= n) break; if (!(a[i + j] == 'g' && a[i + j + 1] == 'o')) break; r = i + j + 1; } if (r) { ps.push_back(make_pair(r, i)); } } if (ps.empty()) { for (int i = 0; i < n; i++) { cout << a[i]; } cout << endl; return; } sort(ps.begin(), ps.end()); vector<P> ansP; ansP.push_back(ps[0]); //可能访问无效内存 for (int i = 1; i < ps.size(); i++) { if (ps[i].second > ps[i - 1].first) { ansP.push_back(ps[i]); } } int it = 0; for (int i = 0; i < n; i++) { if (it == ansP.size() || i < ansP[it].second) cout << a[i]; else { cout << "***"; i = ansP[it++].first; } } cout << endl;}int main(){ //freopen("in.txt", "r", stdin); //freopen("out1.txt", "w", stdout); while (scanf("%d\n", &n) != EOF) { solve(); }}
0 0
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 2) A. Interview wi
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- 【解题报告】Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 总结
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3)
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) F
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017
- Codeforces Round #380 (Div. 2,Based on Technocup 2017 - Elimination Round 2)C - Road to Cine//
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A-C
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- 对关键字volatile的认识
- hbase Caused by: java.lang.ClassNotFoundException: com.google.common.util.concurrent.ThreadFactoryBu
- SQLserver学习day02 数据库用户管理 数据库的基本维护
- linux文件目录切换及/dev/null的使用方式
- Java的内存管理(一)
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 2) A. Interview wi
- 前端优化之路
- Oracle 数据库中v$session and v$process浅析
- centOS下vsftpd的安装与配置
- 黑马就业班第六天-xml及Tomcat及http协议
- C语言习题5.22--输出已交换后的两个值
- VisualSVN的安装及冲突的处理
- Ext4 HBox的使用
- C语言指针变量的运算