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

矩阵乘法计算量估算

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;
}
全部评论

相关推荐

昨天 11:15
中南大学 Java
好可爱的hr姐姐哈哈哈哈
黑皮白袜臭脚体育生:兄弟们貂蝉在一起,吕布开了
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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