Zero-complexity Transposition (submitted for retest on the machine)

Foreword:

21. Regardless of whether you can enter the retest or not, record the garbage code written on the road. I originally gnawed on "Algorithm Notes", but I felt too much to do it, so I changed it to the Kingway Computer Test Guide.

Title description:

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.

Enter description

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).

Output description:

For each case, on the first line of the output file print the sequence in the reverse order.

answer

#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;
}

Guess you like

Origin blog.csdn.net/weixin_44897291/article/details/112979382