Saleh127

CF 121B

Sep 30th, 2020 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. string a;
  11. ll c,d,e,f,k,i,j;
  12. cin>>c>>k;
  13. cin>>a;
  14. for(i=0;i<c-1 && k>0;i++)
  15. {
  16. if(a[i]=='4' && a[i+1]=='7')
  17. {
  18. k--;
  19. if(i%2==0)
  20. {
  21. a[i+1]='4';
  22. }
  23. else
  24. {
  25. a[i]='7';
  26. if(i-1>=0 && a[i-1]=='4')
  27. {
  28. i=i-2;
  29. k%=2;
  30. }
  31. }
  32. }
  33. }
  34. cout<<a<<endl;
  35.  
  36. return 0;
  37. }
  38.  
Add Comment
Please, Sign In to add comment