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

提交结果:

相关推荐
技术不好的崎鸣同学14 小时前
[ACTF2020 新生赛]Exec 思路及解法
算法·安全·web安全
Full Stack Developme15 小时前
Java LRU 与 LFU 算法及应用
java·开发语言·算法
Jerry16 小时前
LeetCode 707. 设计链表
算法
疋瓞16 小时前
python和C++对比(1)_数据类型和数据结构
数据结构·c++·python
C语言小火车16 小时前
C++ 堆排序深度精讲:基于完全二叉树的选择排序进化,最坏情况 O(n log n) 的稳定王者
开发语言·c++·算法·排序算法·堆排序
kebidaixu17 小时前
两轮BMS AFE SH367306 I2C 读写时序
算法
智能排队系统_头部供应商17 小时前
RK3588边缘网关改造银行排队系统实战
算法
东方佑17 小时前
临界分词的存在性与最优性:从统计临界态到神经语言模型的双语实证检验
人工智能·算法·语言模型
Fabarta17 小时前
从 0 实现 ChatGPT 风格的流式对话 UI
算法·架构