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

提交结果:

相关推荐
lvxiangyu114 小时前
MPPI 算法证明重构:基于无穷维泛函变分与 KL 散度的构造性推导
算法·重构·最优控制·随机最优控制
2301_818419014 小时前
C++中的解释器模式变体
开发语言·c++·算法
爱学习的大牛1234 小时前
windows tcpview 类似功能 c++
c++
ab1515175 小时前
3.25完成*23、*24、*28、*30、*33、*38、*39、*40
算法
颜酱5 小时前
回溯算法实战练习(3)
javascript·后端·算法
biter down5 小时前
C++11 统一列表初始化+std::initializer_list
开发语言·c++
ShineWinsu6 小时前
爬虫对抗:ZLibrary反爬机制实战分析技术文章大纲
c++
小王不爱笑1326 小时前
G1 GC 的核心基础:Region 模型的补充细节
java·jvm·算法
小王不爱笑1327 小时前
三色标记算法
算法
charlie1145141917 小时前
通用GUI编程技术——Win32 原生编程实战(十六)——Visual Studio 资源编辑器使用指南
开发语言·c++·ide·学习·gui·visual studio·win32