Something went wrong. Try again.
My leetcode submissions.
Something went wrong. Try again.
1.0 kB · 43 lines
C++
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344#include <bits/stdc++.h>#include <ranges>namespace ra = std::ranges;namespace vi = std::ranges::views;using namespace std::string_literals;using namespace std;#include <cctype>
auto copy_reverse(auto const& s) noexcept -> auto{ auto tmp = s; ra::reverse(tmp); return tmp;}
auto isPalindrome(string s) -> bool{ auto begin = s.cbegin(); auto end = s.cend() - 1; auto const mid = ZZ for (; begin != end; ++begin, --end) { /* while (begin != s.end() && not isalnum(*begin)) ++begin; while (rbegin != s.rend() && not isalnum(*rbegin)) ++rbegin; */ auto const& f = char(toupper(*begin)); auto const& l = char(toupper(*end)); cout << "(" << f << ", " << l << ")\n"; } cout << endl; return ra::equal(copy_reverse(s), s);}
auto main() -> int{ auto s = "A man, a plan, a canal: Panama"s; cout << boolalpha << isPalindrome(s) << endl; s = "race a car"s; cout << boolalpha << isPalindrome(s) << endl; s = " "s; cout << boolalpha << isPalindrome(s) << endl; return 0;}