Number Palindron


SUBMITTED BY: Guest

DATE: Sept. 18, 2014, 6:36 p.m.

FORMAT: C++

SIZE: 1.1 kB

HITS: 581

  1. #include <iostream>
  2. #include <string>
  3. #include <chrono>
  4. #include <thread>
  5. using namespace std;
  6. bool czyPalindron(string s);
  7. void sprawdzLiczby(unsigned init, unsigned off);
  8. static const unsigned long long int DO_ILU = 1e8; //18446744073709551614; (1.84e19)
  9. int main()
  10. {
  11. auto start = chrono::high_resolution_clock::now();
  12. thread t1(sprawdzLiczby, 1, 4);
  13. thread t2(sprawdzLiczby, 2, 4);
  14. thread t3(sprawdzLiczby, 3, 4);
  15. thread t4(sprawdzLiczby, 4, 4);
  16. t1.join();
  17. t2.join();
  18. t3.join();
  19. t4.join();
  20. auto end = chrono::high_resolution_clock::now();
  21. cout << "Czas: " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
  22. return 0;
  23. }
  24. bool czyPalindron(string s)
  25. {
  26. for (auto p = s.begin(), k = s.end() - 1; p != k && p < k; p++, k--)
  27. {
  28. if (*p != *k)
  29. {
  30. return 0;
  31. }
  32. }
  33. return 1;
  34. }
  35. void sprawdzLiczby(unsigned init, unsigned off)
  36. {
  37. for (; init <= DO_ILU; init += off)
  38. {
  39. if (czyPalindron(to_string(init)))
  40. {
  41. cout << init << endl;
  42. }
  43. }
  44. }

comments powered by Disqus