题解 | #【模板】栈#

【模板】栈

https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf

#include <any>
#include <cmath>
#include <iostream>
#include <malloc.h>
#include <string>
using namespace std;

void top(int *st, int* &st_top){
    if (st == st_top) {
        cout<<"error"<<endl;
    }else {
        cout<<*st_top<<endl;
    } 
}

void push(int * st, int* &st_top, int num){
    st_top++;
    *st_top=num;
}

void pop(int *st, int* &st_top){
    if (st != st_top) {
        top(st, st_top);
        st_top--;
    }else {
        cout<<"error"<<endl;
    }
}


int main() {
    int n, i=0;
    int st[100000];
    int *st_top = st;
    string s;int num;
    cin >> n;
    getline(cin, s);
    while (i<n) {
        getline(cin, s);
        // cout<<s<<endl;
        num = 0;
        int pos = s.find(' ');
        if(pos==4){
            
            int k=s.substr(5,s.size()).size();
            
            for(auto x: s.substr(5,s.size())){
                num = num + (int)(x -'0')*pow(10, k-1);
                k--;
                // cout<<(int)(x -'0')<<" "<<num<<endl;
            }
            
            // static_cast<int>();
            push(st, st_top, num);
        }else {
            if (s=="pop") {
                pop(st, st_top);
            }else {
                top(st, st_top);
            }
        }
        // cout<<s<<" "<<pos<<endl;
        i++;
    }
    
    // push(st, st_top, 1);
    // top(st, st_top);
    // pop(st, st_top);
    // top(st, st_top);
    // top(st, st_top);



    // cout<<sizeof(st);
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

03-05 17:03
已编辑
浙江工商大学 C++
陈好好wy:整体看下来有点空空的感觉,可以把每一段项目经历都再完善一下,然后用小标题的形式写个两到三条,目前看有点太简单了,不太能看出具体在这个项目里做了什么工作。还是要尽量把自己做的工作以量化的形式体现在简历上呢。
双非本科求职如何逆袭
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 一张图晒出你司的标语 #
4472次浏览 78人参与
# 找AI工作可以去哪些公司? #
10192次浏览 322人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
15780次浏览 230人参与
# 你的实习产出是真实的还是包装的? #
20951次浏览 346人参与
# 从事AI岗需要掌握哪些技术栈? #
9889次浏览 397人参与
# 春招至今,你的战绩如何? #
68165次浏览 603人参与
# 米连集团26产品管培生项目 #
13505次浏览 286人参与
# AI面会问哪些问题? #
29225次浏览 638人参与
# 你做过最难的笔试是哪家公司 #
36179次浏览 319人参与
# 中国电信笔试 #
32411次浏览 302人参与
# 金三银四,你的春招进行到哪个阶段了? #
22601次浏览 284人参与
# 投递几十家公司,到现在0offer,大家都一样吗 #
341263次浏览 2176人参与
# 同bg的你秋招战况如何? #
212268次浏览 1121人参与
# 哪些公司真双非友好? #
69843次浏览 289人参与
# 如何准备秋招 #
78326次浏览 868人参与
# 阿里笔试 #
179514次浏览 1324人参与
# 应届生被毁约被毁意向了怎么办 #
63364次浏览 305人参与
# 机械人避雷的岗位/公司 #
62728次浏览 393人参与
# 小马智行求职进展汇总 #
25151次浏览 80人参与
# 第一份工作一定要去大厂吗 #
15303次浏览 129人参与
# 担心入职之后被发现很菜怎么办 #
291437次浏览 1210人参与
# 为了减少AI幻觉,你注入过哪些设定? #
26336次浏览 310人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务