Task: | Monistus |
Sender: | snowflake |
Submission time: | 2024-02-12 18:13:32 +0200 |
Language: | C++ (C++11) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'std::string process(const string&)': input/code.cpp:9:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 9 | while (i < s.size()) | ~~^~~~~~~~~~ input/code.cpp:14:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 14 | if (i + repeatCount >= s.size()) | ~~~~~~~~~~~~~~~~^~~~~~~~~~~ input/code.cpp: In function 'int main()': input/code.cpp:38:5: error: 'string' was not declared in this scope; did you mean 'std::string'? 38 | string soho; | ^~~~~~ | std::string In file included from /usr/include/c++/11/iosfwd:39, from /usr/include/c++/11/ios:38, from /usr/include/c++/11/ostream:38, from /...
Code
#include <iostream>#include <string>std::string process(const std::string& s){std::string result = "";int i = 0;while (i < s.size()){if (isdigit(s[i])) {int repeatCount = s[i] - '0'; // Convert digit character to integerint substrStart = i + 1;if (i + repeatCount >= s.size()){break; // Not enough characters left to duplicate}// Repeat the substringfor (int j = 0; j < repeatCount; ++j){result += s.substr(substrStart, repeatCount);}i += repeatCount + 1; // Skip ahead past the digit and duplicated substring}else{result += s[i]; // Copy letters as isi++;}}return result;}int main(){string soho;std::cin >> soho;std::string oute = process(soho);std::cout << oute;return 0;}