From 0052ec63ca70eaa6d9ffb1926c294dbfd85f8c05 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Wed, 18 Sep 2024 20:18:52 +0100 Subject: - Added solutions by Paulo Custodio. - Added solutions by Peter Campbell Smith. - Added solutions by Robert Ransbottom. - Added solutions by Feng Chang. - Added solutions by PokGoPun. - Added solutions by Peter Pentchev. - Added solutions by Santiago Leyva. - Added solutions by Robbie Hatley. - Added solutions by Ulrich Rieke. - Added solutions by Laurent Rosenfeld. --- challenge-287/ulrich-rieke/cpp/ch-2.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 challenge-287/ulrich-rieke/cpp/ch-2.cpp (limited to 'challenge-287/ulrich-rieke/cpp/ch-2.cpp') diff --git a/challenge-287/ulrich-rieke/cpp/ch-2.cpp b/challenge-287/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..b5dc14d07a --- /dev/null +++ b/challenge-287/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +int main( ) { + std::cout << "Enter a string!\n" ; + std::string word ; + std::cin >> word ; + std::string inte {R"(^[-+]?\d+([eE]?[-+]?\d+)*$)"} ; + std::string decifirst {R"(^[-+]?\d+\.([eE]?[-+]?\d+)*$|^[-+]?\d+\.\d+([eE]?[+-]?\d+)*$)"} ; + std::string decisecond {R"(^[+-]?\.\d+([eE]?[+-]?\d+$)*$)" } ; + std::regex integer( inte ) ; + std::regex decimalfirst ( decifirst ) ; + std::regex decimalsecond ( decisecond ) ; + if ( std::regex_match( word , integer ) || std::regex_match( word , decimalfirst ) || + std::regex_match( word , decimalsecond ) ) + std::cout << "true" ; + else + std::cout << "false" ; + std::cout << '\n' ; + return 0 ; +} -- cgit