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

提交结果:

相关推荐
祖力5521 分钟前
Linux应用软件编程:目录IO与framebuffer
linux·运维·算法·framebuffer·目录io
名字还没想好☜27 分钟前
Go 用 slices/maps 标准库泛型函数:告别手写 Contains、Sort、去重(Go 1.21)
开发语言·后端·算法·golang·go
地平线开发者28 分钟前
【模型轻量化专题】深度学习模型为什么需要轻量化
算法
_Narcissus_1 小时前
链表算法题和静态链表
数据结构·c++·笔记·算法·链表·ai·力扣
布莱克6051 小时前
C++拷贝构造与拷贝赋值运算符的区别详解
开发语言·c++
Lyyaoo.1 小时前
【普通数组】【中等】除了自身以外数组的乘积
数据结构·算法·leetcode
threerocks1 小时前
《The AI-Native SDLC Playbook》万字拆解
算法·aigc·ai编程
夏玉林的学习之路2 小时前
算法8.环形队列
算法
啦啦啦啦啦zzzz2 小时前
时间轮定时器
linux·服务器·网络·c++·定时器
O。O蛋黄酥啊2 小时前
GraphRAG 和 LightRAG 详解与对比
人工智能·python·算法·rag·graphrag·lightrag