请帮我把代码中的to_string函数替换成相同作用的代码:#include iostream#include string#include algorithmusing namespace std;int main string s; cin s; int len = slength; while true bool flag = false;
#include
string int_to_string(int num) { string res = ""; while (num > 0) { res += (char)(num % 10 + '0'); num /= 10; } reverse(res.begin(), res.end()); return res; }
int main() { string s; cin >> s; int len = s.length(); while (true) { bool flag = false; for (int i = 0; i < len; ) { int j = i + 1; while (j < len && s[j] == s[i]) j++; if (j - i > 1) { s.replace(i, j - i, string(1, toupper(s[i])) + int_to_string(j - i)); len = s.length(); flag = true; } else { i = j; } } if (!flag) break; reverse(s.begin(), s.end()); } cout << s << endl; return 0;
原文地址: https://www.cveoy.top/t/topic/c0A3 著作权归作者所有。请勿转载和采集!