fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. void doit(int N, int add) {
  9. if (N == 4) {
  10. cout << 6+add << " to " << -1+add << endl;
  11. cout << 3+add << " to " << 6+add << endl;
  12. cout << 0+add << " to " << 3+add << endl;
  13. cout << 7+add << " to " << 0+add << endl;
  14. } else if (N == 5) {
  15. cout << 8+add << " to " << -1+add << endl;
  16. cout << 3+add << " to " << 8+add << endl;
  17. cout << 6+add << " to " << 3+add << endl;
  18. cout << 0+add << " to " << 6+add << endl;
  19. cout << 9+add << " to " << 0+add << endl;
  20. } else if (N == 6) {
  21. cout << 10+add << " to " << -1+add << endl;
  22. cout << 7+add << " to " << 10+add << endl;
  23. cout << 2+add << " to " << 7+add << endl;
  24. cout << 6+add << " to " << 2+add << endl;
  25. cout << 0+add << " to " << 6+add << endl;
  26. cout << 11+add << " to " << 0+add << endl;
  27. } else if (N == 7) {
  28. cout << 8+add << " to " << -1+add << endl;
  29. cout << 5+add << " to " << 8+add << endl;
  30. cout << 12+add << " to " << 5+add << endl;
  31. cout << 3+add << " to " << 12+add << endl;
  32. cout << 9+add << " to " << 3+add << endl;
  33. cout << 0+add << " to " << 9+add << endl;
  34. cout << 13+add << " to " << 0+add << endl;
  35. } else {
  36. cout << 2*N-2+add << " to " << -1+add << endl;
  37. cout << 3+add << " to " << 2*N-2+add << endl;
  38. doit(N-4, 4+add);
  39. cout << 0+add << " to " << 2*N-5+add << endl;
  40. cout << 2*N-1+add << " to " << 0+add << endl;
  41. }
  42. }
  43.  
  44. main() {
  45. /*s = "....BABABA"; lidx = -3; doit(3);
  46.   s = "..BABABABA"; lidx = -1; doit(4);
  47.   s = "..BABABABABA"; lidx = -1; doit(5);
  48.   s = "..BABABABABABA"; lidx = -1; doit(6);
  49.   s = "..BABABABABABABA"; lidx = -1; doit(7);
  50.   s = "..BABABABABABABABA"; lidx=-1; doit(8);*/
  51.  
  52. int N;
  53. while (cin >> N) {
  54. if (N == 3) {
  55. cout << "2 to -1" << endl;
  56. cout << "5 to 2" << endl;
  57. cout << "3 to -3" << endl;
  58. } else {
  59. doit(N, 0);
  60. }
  61. }
  62. }
Success #stdin #stdout 0s 16064KB
stdin
20
stdout
38 to -1
3 to 38
34 to 3
7 to 34
30 to 7
11 to 30
26 to 11
15 to 26
22 to 15
19 to 22
16 to 19
23 to 16
12 to 23
27 to 12
8 to 27
31 to 8
4 to 31
35 to 4
0 to 35
39 to 0