解Zero-complexity Transposition

Zero-complexity Transposition

https://www.nowcoder.com/practice/c54775799f634c72b447ef31eb36e975

//描述
//给你一个整数序列。
//序列的零复杂度换位与此序列相反。
//您的任务是编写一个程序,打印给定序列的零复杂度换位。
//输入描述:
//对于每种情况,输入文件的第一行包含一个整数n长度
//(0<n≤10 000)。
//第二行包含n个整数-1,a2,…,an(-1 000 000 000 000≤ai≤1 000 000 000)。
//输出描述:
//对于每种情况,在输出文件的第一行按相反顺序打印序列。
//输入:
//5
//-3 4 6 -8 9
//输出:
//9 -8 6 4 -3
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
int main(){
    int n,num;
    stack<int> myStack1,myStack2;
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&num);
        myStack1.push(num);
    }
    for(int j = 0;j < n;j++){
        int top=myStack1.top();
        myStack1.pop();
        myStack2.push(top);
        printf("%d ",top);
    }

}

全部评论

相关推荐

06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务