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

提交结果:

相关推荐
独自破碎E20 小时前
【二分法】寻找峰值
算法
mit6.82420 小时前
位运算|拆分贪心
算法
ghie909020 小时前
基于MATLAB的TLBO算法优化实现与改进
开发语言·算法·matlab
恋爱绝缘体120 小时前
2020重学C++重构你的C++知识体系
java·开发语言·c++·算法·junit
wuk99820 小时前
VSC优化算法MATLAB实现
开发语言·算法·matlab
Z1Jxxx21 小时前
加密算法加密算法
开发语言·c++·算法
乌萨奇也要立志学C++21 小时前
【洛谷】递归初阶 三道经典递归算法题(汉诺塔 / 占卜 DIY/FBI 树)详解
数据结构·c++·算法
vyuvyucd21 小时前
C++引用:高效编程的别名利器
算法
鱼跃鹰飞1 天前
Leetcode1891:割绳子
数据结构·算法
️停云️1 天前
【滑动窗口与双指针】不定长滑动窗口
c++·算法·leetcode·剪枝·哈希