Advertisement
goshansmails

Untitled

Mar 6th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. void urlify(string& s) {
  7.     int space_quantity = count(s.begin(), s.end(), ' ');
  8.     //ut << space_quantity;
  9.     int i = s.size() - 1;
  10.     s.resize(s.size() + 2 * space_quantity);
  11.     int j = s.size() - 1;
  12.  
  13.     while (i >= 0) {
  14.         if (s[i] == ' ') {
  15.             s[j--] = '0';
  16.             s[j--] = '2';
  17.             s[j--] = '%';
  18.         } else {
  19.             s[j--] = s[i];
  20.         }
  21.         --i;
  22.     }
  23.  
  24.  
  25. }
  26. int main() {
  27.     {
  28.         string s = "my url";
  29.         urlify(s);
  30.         cout << s << endl;
  31.     }
  32.     {
  33.         string s = "     ";
  34.         urlify(s);
  35.         cout << s << endl;
  36.     }
  37.     {
  38.         string s = "a a a a a";
  39.         urlify(s);
  40.         cout << s << endl;
  41.     }
  42.     {
  43.         string s = "";
  44.         urlify(s);
  45.         cout << s << endl;
  46.     }
  47.     {
  48.         string s = "ff ffd ff  ";
  49.         urlify(s);
  50.         cout << s << endl;
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement