#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
using namespace std;
int n;
int temp[1005];
int main() {
scanf("%d", &n);
for (int i = 1;i <= n;++i) {
scanf("%d", &temp[i]);
if (temp[i] % 2 == 0) {
temp[i]--;
}
}
for (int i = 1;i <= n;++i) {
printf("%d ", temp[i]);
}
//system("pause");
return 0;
}
本文介绍了一段C++代码,用于读取整数n,并生成一个包含n个元素的序列,序列中所有元素原本为输入的整数,但若元素为偶数,则将其减一变为奇数。代码首先定义了一个大小为1005的数组temp来存储序列,然后通过两次for循环分别读取输入并修改序列,最后输出修改后的序列。
392

被折叠的 条评论
为什么被折叠?



