A collection of C++ string manipulation exercises for competitive programming (OI) preparation.
exercises/
├── 01_basics/ # String initialization, concatenation, access
├── 02_operations/ # substr, find, replace, number conversion
├── 03_search/ # Advanced search operations
├── 04_regex/ # Regular expressions (std::regex)
└── 05_advanced/ # string_view, split, join, trim, prefix/suffix
python3 runner.pypython3 runner.py 01_basics/01_init.cpp- Each exercise file contains
// FIX THISmarkers - Read the TODO comments to understand what's needed
- Fix the code to make assertions pass
- Run the runner to verify
01_init.cpp- String constructors02_concat.cpp- Concatenation (+, +=, append)03_access.cpp- Character access ( [], at, front, back)04_io.cpp- Input handling (>>, getline)
01_substr.cpp- Substring extraction02_find.cpp- Finding substrings (find, npos)03_replace.cpp- Replace, erase, insert04_numbers.cpp- Number conversion (to_string, stoi)
01_search.cpp- Advanced find operations
01_match.cpp- regex_match for validation02_search.cpp- regex_search to find all matches03_replace.cpp- regex_replace with capture groups
01_string_view.cpp- Zero-copy string_view02_manual_split.cpp- Implement split function03_join.cpp- Implement join function04_trim.cpp- Trim whitespace05_prefix_suffix.cpp- startsWith, endsWith, stripPrefix, stripSuffix
- Python 3
- g++ with C++17 support
- Use
-std=c++17for string_view support - std::regex can be slow in competitive programming - know when to use manual parsing instead
- string_view is crucial for OI performance (no unnecessary copies)