Codeforces 1099 C. Postcard-字符串处理(Codeforces Round #530 (Div. 2))
1 second
256 megabytes
standard input
standard output
Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.
Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.
For example, consider the following string:
This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows:
- candy cane 1: remove the letter w,
- snowflake 1: repeat the letter p twice,
- candy cane 2: leave the letter n,
- snowflake 2: remove the letter w,
- snowflake 3: leave the letter e.
Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages.
Andrey knows that messages from Irina usually have a length of kk letters. Help him to find out if a given string can encode a message of kkletters, and if so, give an example of such a message.
The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed 200200.
The second line contains an integer number kk (1≤k≤2001≤k≤200), the required message length.
Print any message of length kk that the given string can encode, or «Impossible» if such a message does not exist.
hw?ap*yn?eww*ye*ar
12
happynewyear
ab?a
2
aa
ab?a
3
aba
ababb
5
ababb
ab?a
1
Impossible
题意就是给你一个字符串,其中?可以有两种操作,1.将前面的字母放到当前位置,其实就是去掉?2.去掉前面的字母,其实就是去掉前面的字母去掉?
*的有三种操作,1.将前面的字母放到当前位置,就是去掉* 2.去掉前面的字母,就是去掉前面的字母和* 3.前面的字母可以重复任意次
假设是abc*,可以是abc,可以是ab,可以是abcccccc,就是这样的,给你一个字符串,问你能不能将字符串变成要求的长度,最后的字符串不能有?和*。
直接将纯字母的长度先找出来,然后判断再进行操作就可以了。
代码:
//C
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=1e5+; char s[]; int main()
{
scanf("%s",s);
int n;
cin>>n;
int len=strlen(s);
int candy=,snow=;
for(int i=;i<len;i++){
if(s[i]=='?') candy++;
else if(s[i]=='*') snow++;
}
int l=len-candy-snow;
if(l==n){
for(int i=;i<len;i++){
if(s[i]!='?'&&s[i]!='*') cout<<s[i];
}
cout<<endl;
}
else if(l<n&&snow>){
int c;
for(int i=;i<len;i++){
if(s[i]=='?') s[i]='#';
if(s[i]=='*'){
if(l<n){
c=n-l;
s[i]='!';
//cout<<s[i]<<endl;
l=n;
}
else{
s[i]='#';
}
}
}
for(int i=;i<len;i++){
if(s[i]!='#'){
if(s[i]=='!'){
for(int j=;j<c;j++)
cout<<s[i-];
}
else cout<<s[i];
}
}
cout<<endl;
}
else if(l>n&&l-(candy+snow)<=n){
for(int i=;i<len;i++){
if((s[i]=='?'||s[i]=='*')&&l>n){
s[i-]='#';
s[i]='#';
l--;
}
else if(s[i]=='?'||s[i]=='*')
s[i]='#';
}
for(int i=;i<len;i++){
if(s[i]!='#') cout<<s[i];
}
cout<<endl;
}
else cout<<"Impossible"<<endl;
}
Codeforces 1099 C. Postcard-字符串处理(Codeforces Round #530 (Div. 2))的更多相关文章
- Codeforces 1099 D. Sum in the tree-构造最小点权和有根树 贪心+DFS(Codeforces Round #530 (Div. 2))
D. Sum in the tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 1099 B. Squares and Segments-思维(Codeforces Round #530 (Div. 2))
B. Squares and Segments time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces 1099 A. Snowball-暴力(Codeforces Round #530 (Div. 2))
A. Snowball time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #530 (Div. 2) A,B,C,D
A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)
D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...
- Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)
https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...
- Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)
题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...
- Codeforces Round #530 (Div. 2) Solution
A. Snowball 签. #include <bits/stdc++.h> using namespace std; ], d[]; int main() { while (scanf ...
随机推荐
- iframe的使用及操作
一.iframe的使用方法: 在一个页面中加入iframe代码,例如: <div class="myiframe"> <iframe src="test ...
- 图论:Floyd-多源最短路、无向图最小环
在最短路问题中,如果我们面对的是稠密图(十分稠密的那种,比如说全连接图),计算多源最短路的时候,Floyd算法才能充分发挥它的优势,彻彻底底打败SPFA和Dijkstra 在别的最短路问题中都不推荐使 ...
- Flume入门——Selector、Chanel等
1.selector (http://blog.csdn.net/looklook5/article/details/40430965) (http://blog.csdn.net/xiao_jun_ ...
- spring怎么实现单例模式?
Spring学习之路——单例模式和多例模式 在Spring中,bean可以被定义为两种模式:prototype(多例)和singleton(单例) singleton(单例):只有一个共享的实例存 ...
- Jmeter 重要测试指标释义
Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...
- 【51NOD-0】1008 N的阶乘 mod P
[算法]简单数学 [题解]多项式展开:(a*b)%p=(a%p*b%p)%p #include<cstdio> #include<algorithm> #define rep( ...
- 深入理解Spring MVC(山东数漫江湖)
初始工程 使用Spring Boot和web,thymeleaf的starter来设置初始工程.xml配置如下: <parent> <groupId>org.springf ...
- Tensorflow 2.0.0-alpha 安装 Linux系统
1.TensorFlow2.0的安装测试 Linux Tensorflow Dev Summit 正式宣布 Tensorflow 2.0 进入 Alpha 阶段. 基于 Anaconda 创建环境一个 ...
- C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?
新建一个Console应用程序,项目名称为“FileSystemWatcher”,Copy代码进,编译后就可以用了.代码如下: using System; using System.Collectio ...
- 2017-3-26 webpack入门(一)
2017-3-26 webpack入门(一) webpack 前端 打包 最近项目里用到了webpack特意总结一下.来源:http://webpackdoc.com 1 概念 1.1 webpack ...