Advertisement
erfanul007

CF C

Jan 5th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6. int cnt,n,ln,i,c=0,nn,u=0,j=0;
  7. string str;
  8. cin>>str;
  9. cin>>n;
  10. ln=str.size();
  11. cnt=ln;
  12. for(i=0;i<ln;i++){
  13. if(str[i]=='?'){
  14. j++;
  15. cnt--;
  16. }
  17. if(str[i]=='*'){
  18. u++;
  19. cnt--;
  20. }
  21. }
  22. nn=abs(cnt-n);
  23. if(cnt<n){
  24. if(u==0)
  25. cout<<"Impossible"<<endl;
  26. else{
  27. c=0;
  28. for(i=0;i<ln;i++){
  29. if(str[i]!='?' && str[i]!='*'){
  30. if(i<ln-1 && str[i+1]=='*'){
  31. cout<<str[i];
  32. while(c!=nn){
  33. c++;
  34. cout<<str[i];
  35. }
  36. }
  37. else
  38. cout<<str[i];
  39. }
  40. }
  41. cout<<endl;
  42. }
  43. }
  44. else{
  45. if(u+j<nn)
  46. cout<<"Impossible"<<endl;
  47. else{
  48. c=0;
  49. for(i=0;i<ln;i++){
  50. if(str[i]!='?' && str[i]!='*'){
  51. if(i<ln-1 && (str[i+1]=='?'|| str[i+1]=='*')){
  52. if(c==nn)
  53. cout<<str[i];
  54. else
  55. c++;
  56. }
  57. else
  58. cout<<str[i];
  59. }
  60. }
  61. cout<<endl;
  62. }
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement