| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 69518 | 孙睿阳 | 数组中元素交换 | C++ | Accepted | 1 MS | 268 KB | 397 | 2024-04-05 13:47:35 |
#include<iostream> using namespace std; int a[101]; int main(){ int n,temp; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } if(n%2==0){ for(int j=1;j<=n-1;j=j+2){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } else{ for(int j=1;j<=n-2;j=j+2){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } for(int y=1;y<=n;y++){ cout<<a[y]<<' '; } return 0; }