CF1006A 题解
题意
给定一个数组,2i 和 2i-1能够互相替换,输出元素元素互换后的数组。
题解
很容易发现一个性质:数组中偶数-1,奇数不变
例子:1 2 3(1变为2) ->2 2 3(2变为1) -> 1 1 4(3为变4)-> 1 1 3(4变为3)
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
for(int i = 1, x; i <= n; i++)
{
cin >> x;
if(x % 2 == 0) cout << x - 1 << " ";
else cout << x << " ";
}
return 0;
}