[保研/考研机试] 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")

提交结果:

相关推荐
普通网友几秒前
C++模块化设计原则
开发语言·c++·算法
864记忆3 分钟前
Qt c++的基础语法有哪些?
开发语言·c++·qt
倦王7 分钟前
力扣日刷251117
算法·leetcode·职场和发展
龙泉寺天下行走7 分钟前
Vscode 配置C++ Mingw调试、编译环境-无需修改系统PATH变量的VS Code配置方法
c++·ide·vscode
AA陈超14 分钟前
ASC学习笔记0025:移除所有属性集
c++·笔记·学习·ue5·虚幻引擎
Genevieve_xiao26 分钟前
【数据结构】【xjtuse】八股文单元小测
数据结构·算法
QT 小鲜肉35 分钟前
【Linux常用命令大全】在 Linux 系统下 Git + Vim编辑器常用指令完全指南(亲测有效)
linux·开发语言·c++·笔记·git·编辑器·vim
Xの哲學36 分钟前
Linux slab分配器深度剖析:从原理到实践
linux·服务器·算法·架构·边缘计算
oioihoii2 小时前
现代C++:一场静默的革命,告别“C with Classes”
c语言·jvm·c++
普通网友2 小时前
C++中的组合模式
开发语言·c++·算法