Codeforces Round 863 (Div. 3) 1811A. Insert Digit Solution


 

Problem Link  : https://codeforces.com/contest/1811/problem/A

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. void solve() {
  5. int n, d;
  6. cin >> n >> d;
  7. string s;
  8. cin >> s;
  9. for (int i = 0; i < n; ++i) {
  10. if (s[i] - '0' >= d) {
  11. cout << s[i];
  12. } else {
  13. cout << d;
  14. for (int j = i; j < n; ++j) {
  15. cout << s[j];
  16. }
  17. cout << endl;
  18. return;
  19. }
  20. }
  21. cout << d << endl;
  22. }
  23. int32_t main() {
  24. ios_base::sync_with_stdio(0);
  25. cin.tie(0);
  26. int t;
  27. cin >> t;
  28. while (t--) {
  29. solve();
  30. }
  31. return 0;
  32. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.