Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <math.h>
- #include <cstdlib>
- #include <iomanip>
- #include <cmath>
- #include <string>
- #include <vector>
- using namespace std;
- int mas[10000];
- int main() {
- string str;
- cin >> str;
- int n, k;
- if (str == "forward") {
- cin >> n >> k;
- int flag = 1;
- for (int i = 0; i < k; i++) {
- cin >> mas[i];
- if (mas[i] == 1) flag = 0;
- }
- if (k == 1) {
- if (mas[0] == n) {
- cout << "first ";
- }
- else cout << "second " << mas[0];
- }
- else if (flag) {
- cout << "second ";
- for (int i = 0; i < k; i++) {
- cout << mas[i] - 1 << " ";
- }
- }
- else {
- cout << "first ";
- if (mas[k - 1] == n) {
- for (int i = 0; i < k - 1; i++) {
- cout << mas[i] << " ";
- }
- }
- else {
- for (int i = 1; i < k; i++) {
- cout << mas[i] << " ";
- }
- }
- }
- }
- else {
- cin >> n >> k >> str;
- if (str == "first") {
- int flag = 0;
- for (int i = 0; i < k - 1; i++) {
- cin>>mas[i];
- if (mas[i] == 1) flag = 1;
- }
- if (flag) {
- for (int i = 0; i < k - 1; i++) {
- cout << mas[i] << " ";
- }
- cout << n;
- }
- else if (k == 1) {
- cout << n;
- }
- else {
- cout << "1 ";
- for (int i = 0; i < k - 1; i++) {
- cout << mas[i] << " ";
- }
- }
- }
- else {
- for (int i = 0; i < k; i++) {
- cin >> mas[i];
- }
- if (k == 1) {
- cout << mas[0];
- }
- else {
- for (int i = 0; i < k; i++) {
- cout << mas[i] + 1 << " ";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement