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

提交结果:

相关推荐
INGNIGHT17 分钟前
944 · 最大子矩阵(前缀和)
数据结构·c++·算法
All for pursuit.1 小时前
【动态规划-6】96.不同的二叉搜索树
数据结构·c++·算法·leetcode·动态规划
rou1 小时前
Attention(注意力机制)
算法
信奥卷王2 小时前
[GESP202609 六级] 数组划分
数据结构·算法
大鹏的NLP博客2 小时前
C++ 内存安全的未来:从 Safety Profiles 到 Safe C++
c++·内存安全
牧羊人.3332 小时前
动手学深度学习 07|Resnet网络与迁移学习
网络·人工智能·深度学习·神经网络·算法·cnn·迁移学习
程序员zgh2 小时前
C++ erase() 函数用法
c语言·开发语言·c++·学习
All for pursuit.3 小时前
【并查集-2】399.除法求值
数据结构·c++·算法·leetcode
迪丽热爱3 小时前
一、C语言概述与程序结构
c语言·开发语言·算法
码爸3 小时前
动态规划介绍
算法·动态规划