跳到正文

个人记录

T615662 移动数组

rgjjy约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月9日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v1当前

题目

T615685 日期回文

错误原因:

没找出错误原因

思路

1.输入
2.while死循环
3.定义一个t
4.t的值是a[n]
5.for 移位
6.a[1]=t
7.for输出a[i] endl

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,a[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	while(1==1)//死循环
	{
		int t=a[n];
		for(int i=n;i>=2;i--)//移位
		{
			a[i]=a[i-1];	
		}
		a[1]=t;
		for(int i=1;i<=n;i++)//输出
		{
			cout<<a[i]<<" ";
		}
    cout<<endl;
	}
	return 0;	
} 
原文