fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <numeric>
  4. //#include <iterator>
  5.  
  6. int cw(int first, int second) {
  7. const int arr[] = {20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5};
  8. auto arr_end = std::cend(arr);
  9. auto f = std::find(std::cbegin(arr), arr_end, first);
  10. auto s = std::find(f, arr_end, second);
  11. if (s != arr_end) ++s;
  12. return std::accumulate(f, s, 0,
  13. [](int a, int b){
  14. int res = a + b;
  15. std::cout << a << " + " << b << " = " << res << std::endl;
  16. return res;
  17. }
  18. );
  19. }
  20.  
  21. int main() {
  22. int res = cw(18, 2);
  23. std::cout << "result = " << res;
  24. return 0;
  25. }
Success #stdin #stdout 0s 5680KB
stdin
Standard input is empty
stdout
0 + 18 = 18
18 + 4 = 22
22 + 13 = 35
35 + 6 = 41
41 + 10 = 51
51 + 15 = 66
66 + 2 = 68
result = 68