[C++] The hard way - a lot of string manipulation[C++] The hard way - a lot of string manipulation

🔗

URL Shortener

Week 11, 2026

#include #include #include #include #include #include using namespace std; void strev(char *str); char* fromDeciCh(char res[], int base, int inputNum); char reVal(int num); string fromDeciStr(string& res, int base, int inputNum); int SetNextIncr(int incr); int main() { int base = 36; char res[100]; string resStr = ""; int inputNum = 0; int increment = 0; string incrStr = ""; string returnDeclStr; string altstr = ""; int strlength = 0; for(int second = 0; second < 2611; second++) { increment = second; incrStr = fromDeciStr(resStr, base, second); strlength = strlen(incrStr.c_str()); if( second == 0) { cout << "0: 000\n"; } else { if(strlength == 1) { altstr = to_string(second) + ": 00" + incrStr + "\n"; cout << altstr; } else if(strlength == 2) { altstr = to_string(second) + ": 0" + incrStr + "\n"; cout << altstr; } else { cout << second << ": " << incrStr << "\n"; } } resStr = ""; for(int first = 0; first < 18; first++) { increment = SetNextIncr(increment); if(increment < 46656) { inputNum = increment; cout << increment << ": "; returnDeclStr = fromDeciStr(resStr, base, inputNum); cout << returnDeclStr << "\n"; resStr = ""; } } } return 0; } //----------------------------------------------------------- void strev(char *str) { int len = strlen(str); int i; for (i = 0; i < len/2; i++) { char temp = str[i]; str[i] = str[len-i-1]; str[len-i-1] = temp; } } //---------------------------------------------------------- char reVal(int num) { if (num >= 0 && num <= 9) return (char)(num + '0'); else return (char)(num - 10 + 'A'); } //--------------------------------------------------------- string fromDeciStr(string& res, int base, int inputNum) { int index = 0; while (inputNum > 0) { res.push_back(reVal(inputNum % base)); index++; inputNum /= base; } reverse(res.begin(), res.end()); return res; } //--------------------------------------------------------- int SetNextIncr(int incr) { int inc = incr + 2611; return inc; }