[保研/考研机试] KY109 Zero-complexity Transposition 上海交通大学复试上机题 C++实现

描述:

You are given a sequence of integer numbers. Zero-complexity transposition of the sequence is the reverse of this sequence. Your task is to write a program that prints zero-complexity transposition of the given sequence.

输入描述:

For each case, the first line of the input file contains one integer n-length of the sequence (0 < n ≤ 10 000). The second line contains n integers numbers-a1, a2, ..., an (-1 000 000 000 000 000 ≤ ai ≤ 1 000 000 000 000 000).

输出描述:

For each case, on the first line of the output file print the sequence in the reverse order.

示例1:

cpp 复制代码
输入:
5
-3 4 6 -8 9

输出:
9 -8 6 4 -3

源代码:

cpp 复制代码
#include<iostream>
#include<stack>
using namespace std;

//例题5.4 Zero-complexity Transposition
int main()
{
	int n;
	cin >> n;
	stack<int> myStack;
	for (int i = 0; i < n; i++) {
		int temp = 0;
		cin >> temp;
		myStack.push(temp);
	}
	cout << myStack.top();
	myStack.pop();
	while (!myStack.empty()) {
		cout << " " << myStack.top();
		myStack.pop();
	}
	cout << endl;

	return 0;
}
// 64 位输出请用 printf("%lld")

提交结果:

相关推荐
AA陈超9 分钟前
从0开始学习 **Lyra Starter Game** 项目
c++·笔记·学习·游戏·ue5·lyra
甄心爱学习16 分钟前
数据挖掘-聚类方法
人工智能·算法·机器学习
q***T58320 分钟前
C++在游戏中的Unreal Engine
c++·游戏·虚幻
保持低旋律节奏21 分钟前
C++——C++11特性
开发语言·c++·windows
星释41 分钟前
Rust 练习册 82:Hamming与字符串处理
开发语言·算法·rust
小张成长计划..2 小时前
【C++】16:模板进阶
c++·算法
AndrewHZ2 小时前
【图像处理基石】如何使用大模型进行图像处理工作?
图像处理·人工智能·深度学习·算法·llm·stablediffusion·可控性
AndrewHZ2 小时前
【图像处理基石】图像处理的基础理论体系介绍
图像处理·人工智能·算法·计算机视觉·cv·理论体系
CoderIsArt2 小时前
SAM-5 核心类体系的 C++ 完整设计
c++·sam5
CS_浮鱼2 小时前
【Linux进阶】mmap实战:文件映射、进程通信与LRU缓存
linux·运维·c++·缓存