fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. int test[] = { 0 ,1 ,2, 3, 4, 5, 6, 7, 8, 9};
  7. int testTo[] = { -1 ,-1 ,-1, -1, -1, -1, -1, -1, -1, -1};
  8. int len = 10;
  9. int block = 3;
  10. int counter = 0;
  11. for (int i = 0; i < len; i = i + block*2)
  12. for (int y = 0; y < block; y++)
  13. for (int z = 0; z < 2; z++)
  14. {
  15. int index = i + y + z*block;
  16. if (index < len)
  17. testTo[counter++] = test[index];
  18. }
  19.  
  20. for (int i = 0; i < len; i++)
  21. cout << testTo[i] << " ";
  22. return 0;
  23. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
0  3  1  4  2  5  6  9  7  8