Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- void urlify(string& s) {
- int space_quantity = count(s.begin(), s.end(), ' ');
- //ut << space_quantity;
- int i = s.size() - 1;
- s.resize(s.size() + 2 * space_quantity);
- int j = s.size() - 1;
- while (i >= 0) {
- if (s[i] == ' ') {
- s[j--] = '0';
- s[j--] = '2';
- s[j--] = '%';
- } else {
- s[j--] = s[i];
- }
- --i;
- }
- }
- int main() {
- {
- string s = "my url";
- urlify(s);
- cout << s << endl;
- }
- {
- string s = " ";
- urlify(s);
- cout << s << endl;
- }
- {
- string s = "a a a a a";
- urlify(s);
- cout << s << endl;
- }
- {
- string s = "";
- urlify(s);
- cout << s << endl;
- }
- {
- string s = "ff ffd ff ";
- urlify(s);
- cout << s << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement