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. gitlab 的使用策略和简单介绍

    gitlab 作为版本控制器,基本使用和github 相同,以下是一些策略和介绍: Git 分支管理策略可以参考下面三个链接: http://www.ruanyifeng.com/blog/2012/ ...

  2. Java中x=x+1 与x+=1 的一点区别

    转载自:http://www.cnblogs.com/heshan664754022/archive/2013/04/01/2994028.html 作者:十年半山 今天同悦姐学到了关于Java的复合 ...

  3. B树及其变种

    B树是为磁盘或其他直接存取的辅助存储设备而设计的一种平衡搜索树.B树类似于红黑树,但它们在降低磁盘I/O操场数方面要更好一些.许多数据库系统使用B树或B树的变种来存储信息. 介绍 常见的动态查找树包括 ...

  4. 洛谷 P1722 矩阵 II

    题目背景 usqwedf 改编系列题. 题目描述 如果你在百忙之中抽空看题,请自动跳到第六行. 众所周知,在中国古代算筹中,红为正,黑为负…… 给定一个1*(2n)的矩阵(usqwedf:这不是一个2 ...

  5. 「模板」网络最大流 FF && EK && Dinic && SAP && ISAP

    话不多说上代码. Ford-Fulkerson(FF) #include <algorithm> #include <climits> #include <cstdio& ...

  6. mysql 服务端事务和客户端事务对比分析

    之前做mysql事务测试的时候都是在mysql服务端存储过程里面包含事务. 例如: CREATE DEFINER=`root`@`localhost` PROCEDURE `Test`(out deb ...

  7. 例子Architecting Android…The clean way?----代码分析

    Presention层:   整个应用启动的时候,就执行依赖的初始化.编译项目之后,Dagger依赖框架使用ApplicationComponent生成一个DaggerApplicationCOmpo ...

  8. 【BZOJ】4530: [Bjoi2014]大融合

    [题意]给定n个点的树,从无到有加边,过程中动态询问当前图某条边两端连通点数的乘积,n<=10^5. [算法]线段树合并+并查集 (||LCT(LCT维护子树信息 LCT维护子树信息(+启发式合 ...

  9. PHP 练习2:投票

    1.建立数据库 表1:DiaoYanTiMu 表2:DiaoYanXuanXiang 2.页面 页面1:投票首页 <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  10. HDU - 5327 Olympiad(一维前缀和)

    Olympiad Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem ...