题解 | #Zero-complexity

Zero-complexity Transposition

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

#include "cstdio"
#include "stack"
#include "vector"
#include "queue"
#include "algorithm"

using namespace std;

bool comp_(int a, int b) {
    return true;
}

// 用栈来解决
int main() {
    int n;
    scanf("%d", &n);
    stack<int> stack;
    int temp;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &temp);
        stack.push(temp);
    }

    while (!stack.empty()) {
        printf("%d ", stack.top());
        stack.pop();
    }
    return 0;
}

void test2() {

    int n;
    scanf("%d", &n);
    vector<int> vec;
    int temp;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &temp);
        vec.push_back(temp);
    }

//    printf("size=%d\n", vec.size());
    for (int i = n - 1; i >= 0; --i) {
        vec.pop_back();
        printf("%d ", vec[i]);
    }
//    printf("\nsize=%d", vec.size());
}

/*
    int n;
    scanf("%d", &n);
    long long int arr[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &arr[i]);
    }

    for (int i = n - 1; i >= 0; --i) {
        printf("%d ", arr[i]);
    }
 */

全部评论

相关推荐

不愿透露姓名的神秘牛友
09-30 19:49
起名星人:蛮离谱的,直接要求转投销售
投递汇川技术等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务