time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print any message of length kk that the given string can encode, or «Impossible» if such a message does not exist.

Examples
input

Copy
hw?ap*yn?eww*ye*ar
12
output

Copy
happynewyear
input

Copy
ab?a
2
output

Copy
aa
input

Copy
ab?a
3
output

Copy
aba
input

Copy
ababb
5
output

Copy
ababb
input

Copy
ab?a
1
output

Copy
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))的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #530 (Div. 2) A,B,C,D

    A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...

  5. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  6. 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号结 ...

  7. Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)

    https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...

  8. Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)

    题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...

  9. Codeforces Round #530 (Div. 2) Solution

    A. Snowball 签. #include <bits/stdc++.h> using namespace std; ], d[]; int main() { while (scanf ...

随机推荐

  1. jsoup select 选择器

    转载自:http://blog.csdn.net/zhejingyuan/article/details/11801027 方法 利用方法:Element.select(String selector ...

  2. MongoDB入门(6)- 我们自己封装的MongoDB-C#版本

    Wisdombud.Mongo 包含内容 MongoDB.Bson.dll MongoDB.Bson.xml MongoDB.Driver.dll MongoDB.Driver.xml Wisdomb ...

  3. http基础(1.了解web及网络基础,2.简单的http协议)

    第一章:了解web及网络基础 1.http:超文本传输协议 2.tcp/ip协议族:通常使用的网络是在tcp/ip协议族的基础上运作的,而http属于它内部的一个子集. 3.tcp/ip协议族按层次分 ...

  4. 数据结构:hash_map

    在C++11以上的开发环境中,请直接把map替换成unordered_map,不要使用hash_map 之前我们专门有一篇介绍哈希表,多维哈希表的博文,当时就是以map举例子,然后说了一句把map替换 ...

  5. Bzoj2832 / Bzoj3874 宅男小C

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 124  Solved: 26 Description 众所周知,小C是个宅男,所以他的每天的食物要靠外 ...

  6. Spring基础使用(一)--------IOC、Bean的XML方式装配

    基础 1.xml文件基础格式: <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns=&q ...

  7. python模块subprocess学习

    当我们想要调用系统命令,可以使用os,commands还有subprocess模块整理如下: os模块: 1. os.system 输出命令结果到屏幕.返回命令执行状态. >>> o ...

  8. java===java基础学习(11)---继承

    继承可以解决代码复用,让编程更加靠近人的思维.当多个类存在相同的属性(变量)和方法时,可以从这些类中抽象出父类,在父类中定义这些相同的属性和方法.所有的子类不需要重新定义这些属性和方法,只需要通过ex ...

  9. python实战===老司机奇技淫巧系列之字符转换成图片

    先放两张效果图:

  10. pam会话函数详解

    pam会话函数详解 http://www.xuebuyuan.com/2223069.html http://blog.itpub.net/15480802/viewspace-1406088/ ht ...