fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <ctime>
  6.  
  7. int main()
  8. {
  9. std::cout << "Superior code written in the superior C++ language by the superior Enforcer." << std::endl;
  10. const std::clock_t startClocks = std::clock();
  11. const std::string input = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth";
  12. const std::string reversed = [&] () -> std::string { std::string reversed = input; std::reverse(reversed.begin(), reversed.end()); return reversed; }();
  13. const std::size_t length = input.length();
  14. const std::string::const_iterator iteratorInput = input.cbegin();
  15. const std::string::const_iterator iteratorReversed = reversed.end();
  16. std::string result;
  17.  
  18. for (std::size_t i = 0, longest = 0; length - i > longest; ++i)
  19. {
  20. for (std::size_t j = i + longest; j < length + 1; ++j)
  21. {
  22. if (std::equal(iteratorInput + i, iteratorInput + j, iteratorReversed - j))
  23. {
  24. result = std::string(iteratorInput + i, iteratorInput + j);
  25. longest = j - i;
  26. }
  27. }
  28. }
  29.  
  30. const std::clock_t clocksTaken = std::clock() - startClocks;
  31. std::cout << "Result: " << result << "." << std::endl;
  32. std::cout << "Time taken: " << (clocksTaken * 1000 / CLOCKS_PER_SEC) << "ms." << std::endl;
  33.  
  34. return EXIT_SUCCESS;
  35. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
Superior code written in the superior C++ language by the superior Enforcer.
Result: ranynar.
Time taken: 0ms.