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

提交结果:

相关推荐
Tianwen_Burning36 分钟前
c++ release下的debug
c++
谦宸、墨白1 小时前
从零开始学C++:二叉树进阶
开发语言·数据结构·c++
hrrrrb1 小时前
【算法设计与分析】贪心算法
算法·贪心算法·代理模式
TracyCoder1231 小时前
LeetCode Hot100(10/100)—— 53. 最大子数组和
算法·leetcode
Howrun7771 小时前
C++ 文件操作全知识点详细讲解
c++
Σίσυφος19002 小时前
霍夫变换vs LS vs RANSAC 拟合直线 MATLAB实现
算法·计算机视觉·matlab
假女吖☌2 小时前
限流算法-redis实现与java实现
java·redis·算法
蒟蒻的贤2 小时前
两数之和。
算法
wen__xvn3 小时前
代码随想录算法训练营DAY27第八章 贪心算法 part01
算法·贪心算法
We་ct3 小时前
LeetCode 125. 验证回文串:双指针解法全解析与优化
前端·算法·leetcode·typescript