题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
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;
}
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;
}