-
Notifications
You must be signed in to change notification settings - Fork 0
/
1099C.cpp
83 lines (82 loc) · 1.76 KB
/
1099C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>
#define intl long long
using namespace std;
int main(){
string s;
cin>>s;
int k;
cin>>k;
int a[s.length()]={0};
for(int i=0;i<s.length();i++){
if(s[i]=='?'){
a[i-1]=-3;
a[i]=-1;
}
if(s[i]=='*'){
a[i-1]=-2;
a[i]=-1;
}
// cout<<a[i]<<" ";
}
//cout<<"\n";
int su=0;
for(int i=0;i<s.length();i++){
su++;
if(a[i]==-1){
su--;
}
}
cout<<su<<"\n";
if(su==k){
for(int i=0;i<s.length();i++){
if(a[i]!=-1)
cout<<s[i];
}
}
else if(su<k){
string p="";
int f=0;
for(int i=0;i<s.length();i++){
if(!a[i] || a[i]==-3 || f){
if(a[i]!=-1)
p+=s[i];
}
else if(a[i]==-2){
int l12=su;
for(int i1=0;i1<=k-l12;i1++){
p+=s[i];
su++;
}
su--;
f=1;
}
}
// cout<<su<<"\n";
if(su==k)
cout<<p<<"\n";
else{
cout<<"Impossible\n";
}
}
else{
string p="";
for(int i=0;i<s.length();i++){
if(su!=k){
if(!a[i]){
p+=s[i];
}
else if(a[i]==-2 || a[i]==-3){
su--;
}
}
else if(su==k){
if(a[i]!=-1){
p+=s[i];
}
}
}
if(su==k)
cout<<p<<"\n";
else cout<<"Impossible\n";
}
}