fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4. #include <cstddef>
  5. #include <algorithm>
  6.  
  7. template<typename InputIteratorType, typename OutputIteratorType>
  8. void CalcDifferences(InputIteratorType First, InputIteratorType Last, OutputIteratorType Target)
  9. {
  10. if(First != Last)
  11. {
  12. for(InputIteratorType Next = First; First != Last; ++First)
  13. {
  14. Target = *++Next - *First;
  15. }
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. enum
  22. {
  23. ArraySize = 10
  24. };
  25. int Array[ArraySize];
  26.  
  27. for(std::size_t i = 0; i < ArraySize; ++i)
  28. {
  29. Array[i] = i + 1;
  30. }
  31.  
  32. typedef std::vector<int> DifferenceContainer;
  33. DifferenceContainer Differences;
  34. CalcDifferences(Array, Array + ArraySize, std::back_insert_iterator<DifferenceContainer>(Differences));
  35.  
  36. if(std::find(Array + 1, Array + ArraySize, Array[0]) == Array + ArraySize)
  37. {
  38. std::cout << "Die Differenz der Elemente ist immer " << Array[0];
  39. }
  40. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Die Differenz der Elemente ist immer 1