Zero-complexity Transposition(上交复试上机)

前言:

21考研,不论能否进复试记录一下准备路上写下的垃圾代码。本来啃《算法笔记》,但是感觉太多了做不完,改做王道机试指南。

题目描述:

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.

解答

#include<iostream>
#include<string>
#include<vector>
#include<stack>
using namespace std;

int main() {
    
    
	int n;
	while (scanf("%d",&n)!=EOF) {
    
    
		stack<long long> s;
		long long temp;
		for (int i = 0; i < n; i++) {
    
    
			scanf("%d",&temp);
			s.push(temp);
		}
		for (int i = 0; i < n; i++) {
    
    
			temp = s.top();
			s.pop();
			printf("%d ",temp);
		}
			
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44897291/article/details/112979382