#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
/**
* @brief Removes all non-numeric characters from a string, returning a new filtered string.
*
* @param input The original string containing alphanumeric and special characters.
* @return std::string A new string containing only numeric digits (0-9).
*/
[[nodiscard]] std::string extractNumericOnly(const std::string& input) {
// Create a copy of the input string to modify and return
std::string result = input;
// C++20 std::erase_if removes all elements that satisfy the predicate (returns true)
std::erase_if(result, [](unsigned char c) {
// Return true if the character is NOT a digit (meaning it gets erased)
return !std::isdigit(c);
});
return result;
}
int main() {
// Optimize standard I/O operations for performance
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
// Test string provided
std::string text = "123c++ 9982programming 10000000000001language";
// Process the string
std::string cleanedText = extractNumericOnly(text);
// Output results
std::cout << "Original: " << text << "\n";
std::cout << "Cleaned: " << cleanedText << "\n";
}
/*
run:
Original: 123c++ 9982programming 10000000000001language
Cleaned: 123998210000000000001
*/