Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<cmath>
- using namespace std;
- int main()
- {
- int cnt,n,ln,i,c=0,nn,u=0,j=0;
- string str;
- cin>>str;
- cin>>n;
- ln=str.size();
- cnt=ln;
- for(i=0;i<ln;i++){
- if(str[i]=='?'){
- j++;
- cnt--;
- }
- if(str[i]=='*'){
- u++;
- cnt--;
- }
- }
- nn=abs(cnt-n);
- if(cnt<n){
- if(u==0)
- cout<<"Impossible"<<endl;
- else{
- c=0;
- for(i=0;i<ln;i++){
- if(str[i]!='?' && str[i]!='*'){
- if(i<ln-1 && str[i+1]=='*'){
- cout<<str[i];
- while(c!=nn){
- c++;
- cout<<str[i];
- }
- }
- else
- cout<<str[i];
- }
- }
- cout<<endl;
- }
- }
- else{
- if(u+j<nn)
- cout<<"Impossible"<<endl;
- else{
- c=0;
- for(i=0;i<ln;i++){
- if(str[i]!='?' && str[i]!='*'){
- if(i<ln-1 && (str[i+1]=='?'|| str[i+1]=='*')){
- if(c==nn)
- cout<<str[i];
- else
- c++;
- }
- else
- cout<<str[i];
- }
- }
- cout<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement