fork download
  1. #include <iostream>
  2. #include <cstdint>
  3. #include <vector>
  4. #include <random>
  5.  
  6. typedef std::vector<std::int64_t> DType;
  7.  
  8. DType MakeVector(const std::size_t& N, const unsigned int& S = 0) {
  9. std::int64_t Range = 16;
  10. std::mt19937 mt(S);
  11. std::uniform_int_distribution<std::int64_t> ui(-Range, Range);
  12.  
  13. DType D;
  14.  
  15. for (std::size_t i = 0; i < N; i++) {
  16. D.push_back(ui(mt));
  17. }
  18.  
  19. return D;
  20. }
  21.  
  22. DType MakeHoge(const DType& D) {
  23. DType R;
  24.  
  25. for (std::size_t i = 0; i < D.size() - 1; i++) {
  26. R.push_back(D[i] - D[i + 1]);
  27. }
  28.  
  29. return R;
  30.  
  31. }
  32.  
  33. bool Show(const DType& D, const DType& R) {
  34.  
  35. for (auto& o : D) {
  36. std::cout << o << ',';
  37. }
  38. std::cout << std::endl;
  39. std::cout << std::endl;
  40. for (auto& o : R) {
  41. std::cout << o*-1 << ',';
  42. }
  43. std::cout << std::endl;
  44.  
  45. return true;
  46. }
  47.  
  48. int main() {
  49. DType D;
  50. DType R;
  51. std::size_t L = 16;
  52. D = MakeVector(L);
  53.  
  54. R = MakeHoge(D);
  55.  
  56. Show(D, R);
  57.  
  58. return 0;
  59.  
  60. }
  61.  
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
2,3,7,11,3,12,1,11,-3,4,5,-4,-2,-7,13,-15,

1,4,4,-8,9,-11,10,-14,7,1,-9,2,-5,20,-28,