#include <string>
#include <sstream>
#include <iostream>

using namespace std;

string hex(unsigned int c)
{
    ostringstream stm ;
    stm << '=' << hex << uppercase << c;
    return stm.str() ;
}

string url_encode(const string& str)
{
    static const string unreserved = "0123456789"
                                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                     "abcdefghijklmnopqrstuvwxyz"
                                     "-_.~" ;
    string result;

	for (int i = 0; i < str.size(); i++) {
		unsigned char c = str[i];
		
		if (unreserved.find(c) != string::npos) {
			result += c;
			cout << c << endl;
		} else {
			result += hex(c);
			cout << hex(c) << endl;
		}
	}
    return result;
}

int main()
{
    string test = "čau";
    string result = url_encode(test);
    //cout << test << '\n' << result << '\n';
}
