题目链接
https://vjudge.net/problem/CodeForces-1006A
题意
给一个数列,依次执行下列操作:
把数列中所有的1变成2,把所有的2变成1,把所有的3变成4,把所有的4变成3……
求最后的数列变成了什么。
思路
- 如果是奇数,则不变
- 如果是偶数,则减一
AC代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI=atan(1.0)*4;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1000000007;
const int maxn = 100010;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, x;
scanf("%d", &n);
scanf("%d", &x);
if(x % 2 == 0)
x--;
printf("%d", x);
for(int i = 2; i <= n; i++)
{
scanf("%d", &x);
if(x % 2 == 0)
x--;
printf(" %d", x);
}
printf("\n");
return 0;
}