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

提交结果:

相关推荐
luj_17686 小时前
残熵算法实时化三大瓶颈突破
c语言·开发语言·网络·经验分享·算法
mCell7 小时前
你以为短链接只是 Hash + 301/302?
后端·算法·架构
因你入海底7 小时前
【考研】2026/7/10
考研·11408
远离UE48 小时前
UE5 compute shader 原子加
开发语言·c++·ue5
C+-C资深大佬8 小时前
C++ 显式类型转换详解:static_cast、dynamic_cast、const_cast、reinterpret_cast
开发语言·c++
KaMeidebaby9 小时前
卡梅德生物技术快报|抗体亲和力成熟工业化调控新机制:差异性浆细胞增殖工艺优化思路
java·开发语言·人工智能·算法·机器学习·架构·spark
luj_17689 小时前
心形曲线轨迹控制三大关键技术
c语言·开发语言·c++·经验分享·算法
取地址符9 小时前
C++学习笔记(基于learn-cxx)(1)
c++·经验分享·笔记·学习
tmlx3I08110 小时前
高光谱拼接算法(六)RANSAC 误匹配剔除
人工智能·算法·机器学习
不相心 -w-10 小时前
基础-滑动窗口-(定长 | 不定长)
算法