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

提交结果:

相关推荐
学学酱快乐21 分钟前
2026年PMP考试生命周期选择决策树精讲:从需求判断到混合型统一框架的应试全攻略
算法·决策树·机器学习·pmp新版考试大纲·pmp新题型·pmp培训哪家好·pmp培训机构推荐
爱和冰阔落32 分钟前
【Linux】Ctrl+C 到底做了什么?从键盘、kill 到 alarm,一次讲清信号的产生
linux·运维·c++·安卓
傅科摆 _ py35 分钟前
动态规划复习
算法·动态规划
水饺编程1 小时前
第5章,[Win32 章节] :贝塞尔样条曲线(一)
c语言·c++·windows·visual studio
Wang's Blog1 小时前
PostgreSQL笔记49:向量检索核心算法、索引调优与过滤策略深度解析
笔记·算法·postgresql
疯狂打码的少年1 小时前
【数据结构】交换类排序:冒泡与快速排序
数据结构·笔记·算法·排序算法
Nil2082 小时前
leetcode 108有序数组转换为二叉搜索树
数据结构·算法·leetcode
高频因子挖掘机2 小时前
QuantDash 成交量单位统一实战:从“手”到“股”的跨市场量化数据清洗全流程
后端·算法·github
程序员打怪兽2 小时前
C++:类与对象,封装,继承,多态,构造/析构,重载/重写
c++
hn小菜鸡2 小时前
LeetCode 763、划分字母区间
数据结构·算法·leetcode