fork(1) download
  1. #include <algorithm>
  2. #include <array>
  3. #include <cstdio>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. #define N 5 // Assumed positive number smaller than str.size()
  11.  
  12. int main() {
  13. const string str("atgctgttg");
  14. const int n1 = N - 1;
  15. vector<array<char, N>> result(str.size() - n1);
  16.  
  17. transform(str.cbegin(), str.cend() - n1, result.begin(), [](const auto& i) {
  18. array<char, N> result;
  19.  
  20. copy_n(&i, N, result.begin());
  21. return result;
  22. });
  23.  
  24. for (auto& i : result) {
  25. printf("%.*s\n", N, &i);
  26. }
  27. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
atgct
tgctg
gctgt
ctgtt
tgttg