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

提交结果:

相关推荐
Yupureki1 天前
《算法竞赛从入门到国奖》算法基础:入门篇-二分算法
c语言·开发语言·数据结构·c++·算法·visual studio
游戏23人生1 天前
c++ 语言教程——16面向对象设计模式(五)
开发语言·c++·设计模式
qq_463408421 天前
React Native跨平台技术在开源鸿蒙中使用WebView来加载鸿蒙应用的网页版或通过一个WebView桥接本地代码与鸿蒙应用
javascript·算法·react native·react.js·开源·list·harmonyos
老王熬夜敲代码1 天前
C++的decltype
开发语言·c++·笔记
Jul1en_1 天前
【算法】位运算
算法
苏州知芯传感1 天前
柔性抓取的“慧眼”:MEMS 3D视觉如何让机器人精准识别无序堆叠的复杂钣金件?
算法·3d·机器人·mems
闻缺陷则喜何志丹1 天前
【C++组合数学】P8106 [Cnoi2021] 数学练习|普及+
c++·数学·洛谷·组合数学
ALex_zry1 天前
C++ const成员函数详解:原理、应用与最佳实践
c++
iAkuya1 天前
(leetcode)力扣100 22相交链表(双指针)
算法·leetcode·链表
chao1898441 天前
基于MATLAB的ADI方法求解偏微分方程详解
开发语言·算法·matlab