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 ...
随机推荐
- 在windows下如何使用密钥对远程登录服务器?
在企业的生产中相信各位朋友都会使用远程登录服务器,这样即高效也非常方便,(服务器在西藏,没有远程技术,公司在北京,你只能到西藏与机器相伴,在这里我使用xshell软件),我们使用ssh 服务登录服务器 ...
- redis linux下的开机启动
redis linux下的环境搭建 http://www.cnblogs.com/zsg88/p/8321644.html 安装完redis-4.0.1后设置linux开机自启动. 1.在re ...
- 【BZOJ2693】jzptab [莫比乌斯反演]
jzptab Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 求 Input 第一行一个 ...
- 【HDU】6012 Lotus and Horticulture (BC#91 T2)
[算法]离散化 [题解] 答案一定存在于区间的左右端点.与区间左右端点距离0.5的点上 于是把所有坐标扩大一倍,排序(即离散化). 让某个点的前缀和表示该点的答案. 初始sum=∑c[i] 在l[i] ...
- Android检测View的可见性
Android中我们经常会用到判断View的可见行,当然有人会说View.VISIBLE就可以了,但是有时候这个真是满足不了,有时候我们为了优化,在View滚到得不可见的时候或者由于滚到只显示了部分内 ...
- 并查集入门--畅通工程(HDU1232)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 畅通工程 Time Limit: 4000/2000 MS (Java/Others) M ...
- Android控件——ToggleButton多状态按钮(实现灯泡的开关)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxoAAAFxCAIAAAB7jkm1AAAgAElEQVR4nOy9eXgUVb7/Dy7j3BnH8T
- Ubuntu中启用关闭Network-manager网络设置问题! 【Server版本】
在UbuntuServer版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改/etc/network/interfaces.具体设置方法如下: (1) UbuntuServer 修改 ...
- 再思linux内核在中断路径内不能睡眠/调度的原因(2010)【转】
转自:http://blog.csdn.net/maray/article/details/5770889 Linux内核中断路径中不能睡眠,为什么? 这里就行了很深入的讨论,值得一看:http:// ...
- wifi驱动移植
目标板:Hi3518 内核版本:linux3.0.8 1.修改makefile #PLATFORM = PC //注释掉 PLATFORM = HI3518 //支持平台 ifeq ($(PLAT ...