前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【第33-34题】作业没完成

【第33-34题】作业没完成

作者头像
小码匠
发布2023-08-31 14:32:53
1450
发布2023-08-31 14:32:53
举报
文章被收录于专栏:小码匠和老码农

碎碎念

今天交作业,完成了50%,P1175,真气人

  • P4387:AC
  • P1739:未作(题目比较简单,自己可以做出来)
  • P1449:AC
  • P1175:30分
    • 这道题思路没问题,码量比较大,测试了几组数据,都过了,应该还有没考虑到的分支,比较悲剧。

今天分享两道题的AC代码

题目:P1449 后缀表达式

题目原文请移步下面的链接

  • https://www.luogu.com.cn/problem/P1449
    • 参考题解:https://www.luogu.com.cn/problem/solution/P1449
  • 标签:OI模拟字符串数据结构
  • 难度:普及-

题解

思路
  • 题目比较简单,题解闪过!
AC代码
代码语言:javascript
复制
#include <bits/stdc++.h>

using namespace std;
#define endl '\n';

void best_coder() {
    string s;
    cin >> s;
    vector<string> c(55);
    int j = 0, t = 0, l = 0;
    for (int i = 0; i < s.size() - 1; ++i) {
        if (s[i] == '.') {
            c[j] = s.substr(t, i - t);
            t = i + 1;
            ++l;
            ++j;
        } else if (s[i] < '0' || s[i] > '9') {
            c[j] = s[i];
            ++j;
            ++l;
            t = i + 1;
        }

    }
    stack<int> ans;
    ans.push(stoi(c[0]));
    int i = 1;
    for (; i < l; ++i) {
        if (c[i] < "0" || c[i] > "9") {
            int a = ans.top();
            ans.pop();
            int b = ans.top();
            ans.pop();
            if (c[i] == "+") {
                ans.push(a + b);
            } else if (c[i] == "-") {
                ans.push(b - a);
            } else if (c[i] == "*") {
                ans.push(a * b);
            } else if (c[i] == "/") {
                ans.push(b / a);
            }
        } else {
            ans.push(stoi(c[i]));
        }
    }
    cout << ans.top();
}

void happy_coder() {

}

int main() {
//    // 提升cin、cout效率
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
//    cout.tie(nullptr);

    // 小码匠
    best_coder();

    // 最优解
    // happy_coder();

    // 返回
    return 0;
}
/**
* 8.3.2.6.*+5./-4.+@
*/

题目:P4387 【深基15.习9】验证栈序列

题目原文请移步下面的链接

  • https://www.luogu.com.cn/problem/P4387
    • 参考题解:https://www.luogu.com.cn/problem/solution/P4387
  • 标签:OI模拟字符串数据结构
  • 难度:普及/提高-

题解

思路
  • 题解继续闪过
AC代码
代码语言:javascript
复制
#include <bits/stdc++.h>

using namespace std;
#define endl '\n';

void best_coder() {
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        vector<int> a(n);
        vector<int> b(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        for (int i = 0; i < n; ++i) {
            cin >> b[i];
        }
        stack<int> s;
        int j = 0;
        for (int i = 0; i < n; ++i) {
            s.push(a[i]);
            while (!s.empty() && s.top() == b[j]) {
                s.pop();
                ++j;
            }
        }
        if (s.empty()) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

void happy_coder() {

}

int main() {
//    // 提升cin、cout效率
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
//    cout.tie(nullptr);

    // 小码匠
    best_coder();

    // 最优解
    // happy_coder();

    // 返回
    return 0;
}

END

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-06-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小码匠和老码农 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目:P1449 后缀表达式
  • 题解
    • 思路
      • AC代码
      • 题目:P4387 【深基15.习9】验证栈序列
      • 题解
        • 思路
          • AC代码
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档