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

提交结果:

相关推荐
取加若则_2 小时前
Linux进程调度:双队列高效管理
linux·算法
Tisfy3 小时前
LeetCode 961.在长度 2N 的数组中找出重复 N 次的元素:5种语言x5种方法(及其变种) —— All By Hand
数据结构·数学·算法·leetcode·题解
蜕变的土豆3 小时前
vcpkg使用教程
c++
小O的算法实验室3 小时前
2024年ESWA SCI1区TOP,容错文化概率粒子群算法+多 AGV 路径规划,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
图先4 小时前
第十八讲多元函数积分学(五)——第二型曲面积分
考研
略无慕艳意4 小时前
C++ 中的 vector
c++
WW_千谷山4_sch4 小时前
洛谷P1120&UVA307 [CERC 1995] 小木棍
c++·算法·深度优先
XLYcmy5 小时前
高级密码猜测生成器AdvancedPasswordGenerator密码生成器程序详细分析
开发语言·python·算法·网络安全·开发工具·源代码·口令安全
冉佳驹5 小时前
C++ ——— 深入解析多态从语法到底层实现的完整知识体系
c++·多态·抽象类·虚函数·虚函数表
im_AMBER6 小时前
Leetcode 93 找出临界点之间的最小和最大距离
c++·笔记·学习·算法·leetcode