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

提交结果:

相关推荐
菜菜的顾清寒18 小时前
力扣HOT100(21)相交链表
算法·leetcode·链表
郝YH是人间理想18 小时前
考研数学二图鉴——矩阵
线性代数·考研·矩阵
zh路西法18 小时前
【ROS2多激光雷达融合】基于ROS2的双2D激光雷达点云融合与遮挡剔除方案
c++·python·机器人
七颗糖很甜18 小时前
开源雷达NEXRAD Level 3 数据完整获取与 Python 处理教程
大数据·python·算法
JXNL@18 小时前
TDK DPX105950DT 射频双工器全解析:从原理、参数到应用设计
算法
池塘的蜗牛18 小时前
FMCW(2)-速度
算法
菜菜的顾清寒18 小时前
力扣hot100(21)搜索二维矩阵 II
算法·leetcode·职场和发展
楼田莉子18 小时前
CMake学习:动态库场景下的应用
c++·后端·学习·软件构建
jingshaoqi_ccc18 小时前
使用QT6创建一个可编辑的表格并导出和载入
c++·qt·表格
️是7818 小时前
信息奥赛一本通—编程启蒙(3380:练65.3 螺旋矩阵)
线性代数·算法·矩阵