Guest User

Untitled

a guest
Jan 14th, 2020
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <math.h>
  7. #include <cstdlib>
  8. #include <iomanip>
  9. #include <cmath>
  10. #include <string>
  11. #include <vector>
  12.  
  13.  
  14. using namespace std;
  15.  
  16.  
  17. int mas[10000];
  18. int main() {
  19. string str;
  20. cin >> str;
  21. int n, k;
  22. if (str == "forward") {
  23. cin >> n >> k;
  24. int flag = 1;
  25. for (int i = 0; i < k; i++) {
  26. cin >> mas[i];
  27. if (mas[i] == 1) flag = 0;
  28.  
  29. }
  30. if (k == 1) {
  31. if (mas[0] == n) {
  32. cout << "first ";
  33. }
  34. else cout << "second " << mas[0];
  35. }
  36. else if (flag) {
  37. cout << "second ";
  38. for (int i = 0; i < k; i++) {
  39. cout << mas[i] - 1 << " ";
  40. }
  41. }
  42. else {
  43. cout << "first ";
  44. if (mas[k - 1] == n) {
  45. for (int i = 0; i < k - 1; i++) {
  46. cout << mas[i] << " ";
  47. }
  48. }
  49. else {
  50. for (int i = 1; i < k; i++) {
  51. cout << mas[i] << " ";
  52. }
  53. }
  54. }
  55. }
  56. else {
  57. cin >> n >> k >> str;
  58. if (str == "first") {
  59. int flag = 0;
  60. for (int i = 0; i < k - 1; i++) {
  61. cin>>mas[i];
  62. if (mas[i] == 1) flag = 1;
  63. }
  64. if (flag) {
  65. for (int i = 0; i < k - 1; i++) {
  66. cout << mas[i] << " ";
  67. }
  68. cout << n;
  69. }
  70. else if (k == 1) {
  71. cout << n;
  72. }
  73. else {
  74. cout << "1 ";
  75. for (int i = 0; i < k - 1; i++) {
  76. cout << mas[i] << " ";
  77. }
  78. }
  79. }
  80. else {
  81. for (int i = 0; i < k; i++) {
  82. cin >> mas[i];
  83.  
  84. }
  85. if (k == 1) {
  86. cout << mas[0];
  87. }
  88. else {
  89. for (int i = 0; i < k; i++) {
  90. cout << mas[i] + 1 << " ";
  91. }
  92. }
  93. }
  94. }
  95.  
  96. }
RAW Paste Data