A. Adjacent Replacements

Mishka got an integer array aa of length nn as a birthday present (what a surprise!).

Mishka doesn’t like this present and wants to change it somehow. He has invented an algorithm and called it “Mishka’s Adjacent Replacements Algorithm”. This algorithm can be represented as a sequence of steps:

Replace each occurrence of 1 in the array aa with 2;
Replace each occurrence of 2 in the array aa with 1;
Replace each occurrence of 3 in the array aa with 4;
Replace each occurrence of 4 in the array aa with 3;
Replace each occurrence of 5 in the array aa with 6;
Replace each occurrence of 6 in the array aa with 5;
……
Replace each occurrence of 109−1109−1 in the array aa with 109109;
Replace each occurrence of 109109 in the array aa with 109−1109−1.
Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i−1,2i2i−1,2i) for each i∈{1,2,…,5⋅108}i∈{1,2,…,5⋅108} as described above.

For example, for the array a=[1,2,4,5,10]a=[1,2,4,5,10], the following sequence of arrays represents the algorithm:

[1,2,4,5,10][1,2,4,5,10] →→ (replace all occurrences of 11 with 22) →→ [2,2,4,5,10][2,2,4,5,10] →→ (replace all occurrences of 22 with 11) →→ [1,1,4,5,10][1,1,4,5,10] →→ (replace all occurrences of 33 with 44) →→ [1,1,4,5,10][1,1,4,5,10] →→ (replace all occurrences of 44 with 33) →→ [1,1,3,5,10][1,1,3,5,10] →→ (replace all occurrences of 55 with 66) →→ [1,1,3,6,10][1,1,3,6,10] →→ (replace all occurrences of 66 with 55) →→ [1,1,3,5,10][1,1,3,5,10] →→ …… →→ [1,1,3,5,10][1,1,3,5,10] →→ (replace all occurrences of 1010 with 99) →→ [1,1,3,5,9][1,1,3,5,9]. The later steps of the algorithm do not change the array.

Mishka is very lazy and he doesn’t want to apply these changes by himself. But he is very interested in their result. Help him find it.

Input
The first line of the input contains one integer number nn (1≤n≤10001≤n≤1000) — the number of elements in Mishka’s birthday present (surprisingly, an array).

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output
Print nn integers — b1,b2,…,bnb1,b2,…,bn, where bibi is the final value of the ii-th element of the array after applying “Mishka’s Adjacent Replacements Algorithm” to the array aa. Note that you cannot change the order of elements in the array.

Examples
inputCopy
5
1 2 4 5 10
outputCopy
1 1 3 5 9
inputCopy
10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000
outputCopy
9999 9 50605065 1 5 89 5 999999999 60506055 999999999
Note
The first example is described in the problem statement.

Hint:奇数两次变换一定会换回来,偶数只变一次。

#include <iostream>
using namespace std;

int a[1005];

int main()
{
    int n;
    while(cin >> n)
    {
        for(int i = 0; i < n; ++i)
            cin >> a[i];
        for(int i = 0; i < n; ++i)
        {
            if(a[i] & 1)
                cout << a[i] << ' ';
            else
                cout << a[i] - 1 << ' ';
        }
        cout << '\n';
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值