Codeforces ~ 1006A ~ Adjacent Replacements(水)

题意

长度为n的数组,你对他按顺序执行以下操作:

1->2,2->1

3->4,4->3

5->6,6->5

1e9+-1->1e9

1e9->1e9-1

...

问执行完的数组?

思路

其实观察一下就发现是把偶数变为-1的奇数即可。

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int t; scanf("%d", &t);
        if (t%2 == 0) t = t-1;
        printf("%d ", t);
    }
    return 0;
}
/*
5
1 2 4 5 10
*/

猜你喜欢

转载自blog.csdn.net/zscdst/article/details/81076307