题解 | #矩阵乘法计算量估算#

矩阵乘法计算量估算

http://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b

#include <bits/stdc++.h>
using namespace::std;

int main()
{
    int num = 0;
    
    while (cin >> num) {
        uint arr[10][2] = {0};
        for (int i = 0; i <num; i++) {
            cin >> arr[i][0] >> arr[i][1];
        }
        int mul = 0;
        string str;
        //getline(cin, str);
        cin >> str;
        stack<pair<uint, uint>> st;
        for (int i = 0; i < str.size(); i++) {
            if ('(' == str[i]) {
                continue;
            } else if (')' == str[i]) {
                auto y = st.top();
                st.pop();
                auto x = st.top();
                st.pop();
                st.push({x.first, y.second});
                mul += x.first * x.second * y.second;
            } else {
                int n = str[i] - 'A';
                st.push({arr[n][0], arr[n][1]});
            }
        }
        cout << mul << endl;
    }
    
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 14:00
不想多说了,什么逆天HR,还要教我礼貌😂
机械打工仔:这不纯傻卵吗,他还操心上别人老板了
投递BOSS直聘等公司7个岗位
点赞 评论 收藏
分享
一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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