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

提交结果:

相关推荐
_日拱一卒17 小时前
LeetCode:17电话号码的字母组合
java·数据结构·算法·leetcode·职场和发展
醉颜凉17 小时前
Scala自定义Monad实战:从理论到应用的完整指南
大数据·算法·scala
奶粉不够17 小时前
用SDL3完成一个扫雷
c++
STY_fish_201217 小时前
KMP-前缀函数
算法
海兰17 小时前
【小程序】考研英语词汇 Flashcard — 详细设计
考研·小程序
feng_you_ying_li17 小时前
Linux 之线程封装,线程的同步与互斥,互斥锁的介绍
linux·c++·算法
星恒随风17 小时前
C++入门(二):函数重载、引用、const引用和 inline 内联函数
开发语言·c++·笔记·学习
basketball61617 小时前
C++ 高级编程:1. 多线程基本操作
开发语言·c++
十五年专注C++开发17 小时前
std::vector<T>到QVector<T>的数据复制方案
c++·vector·iterator模式·qvector
HZ·湘怡18 小时前
二叉树 2 堆
算法