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

提交结果:

相关推荐
影视飓风TIM1 分钟前
C++ 核心语法进阶:【类和对象终章】从对象拷贝到友元与优化(补上期重载)
c++
小鹏linux1 分钟前
鸿蒙PC迁移:Tesseract OCR C++ 三方库鸿蒙适配全记录
c++·ocr·harmonyos
森G2 分钟前
65、UDP协议(拓展选学)---------网络编程
网络·c++·qt·网络协议·tcp/ip·udp
WWW65265 分钟前
代码随想录 打卡第五十八天
开发语言·c++·算法
pen-ai7 分钟前
【HistGBM 系列①】从决策树到梯度提升 —— GBDT 原理精讲
算法·决策树·机器学习
少司府11 分钟前
C++基础入门:_stack_queue 底层奥秘
开发语言·数据结构·c++·栈和队列·queue·stack
Black蜡笔小新16 分钟前
零代码私有化自动化AI算法训练服务器DLTM如何破解企业AI落地难题
人工智能·算法·自动化
liulilittle28 分钟前
回归物理本质:对拥塞控制实验室依赖与公平性误置的反思
网络·tcp/ip·计算机网络·算法·tcp·通信·拥塞控制
牛油果子哥q28 分钟前
unordered_set / unordered_map 底层哈希表精讲,哈希原理、哈希冲突、链地址法、源码结构、有序与无序容器终极选型全解
数据结构·算法·哈希算法·散列表
码上有光31 分钟前
c++: AVL树
开发语言·c++·avl树