Advertisement
unknown_0711

Untitled

Apr 5th, 2023 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. #define ll long long int
  4.  
  5. const int M = 1e9 + 7;
  6.  
  7. int main() {
  8. int t;
  9. cin >> t;
  10. while (t--) {
  11. int n, x;
  12. cin >> n >> x;
  13. string s;
  14. cin >> s;
  15. int req = n; // changed here
  16.  
  17. if (x == 0) {
  18. s.insert(n, "0"); // changed here
  19. cout << s << endl;
  20. }
  21. //int p = stoi(s[i])
  22. else {
  23. vector<int> digits;
  24.  
  25. for (auto x : s)
  26. digits.push_back(x - '0');
  27.  
  28. for (int i = 0; i < n; ++i) {
  29. if (digits[i] < x) {
  30. req = i;
  31. break;
  32. }
  33. }
  34.  
  35. string y;
  36. y = to_string(x);
  37.  
  38. s.insert(req, y);
  39. cout << s << endl;
  40. }
  41. }
  42. return 0;
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement