#include<bits/stdc++.h>
using namespace std;
#define N 100000
int n, res, g, m, k, B;
string s;
int getNum1(string s1) {
int res = 0;
int lf, rg;
while ((lf = s1.find('[')) != s1.npos) {
rg = s1.find(']');
res += (stoi(s1.substr(lf + 1, rg - lf - 1)));
s1 = s1.substr(rg + 1);
}
return res;
}
int getNum2(string s1) {
int res = 0, i = 0;
while (i < s1.size()) {
while (i < s1.size() && s1[i] != '"')i++;
int lf = i;
i++;
while (i < s1.size() && s1[i] != '"')i++;
int rg = i;
i++;
res += rg - lf - 1;
}
return res;
}
int main() {
cin >> n;
getchar();
while (n--) {
getline(cin, s);
int pos = s.find(' ');
string type_str = s.substr(0, pos), str = s.substr(pos + 1);
if (type_str == "int")res += 4 * (count(str.begin(), str.end(), ',') + 1);
else if (type_str == "int[]")res += 4 * getNum1(str);
else if (type_str == "long") res += 8 * (count(str.begin(), str.end(), ',') + 1);
else if (type_str == "long[]")res += 8 * getNum1(str);
else if (type_str == "String")res += getNum2(str);
}
g = res / 1024 / 1024 / 1024, m = res / 1024 / 1024 % 1024, k = res / 1024 % 1024, B = res % 1024;
if (g)cout << g << "GB";
if (m)cout << m << "MB";
if (k)cout << k << "KB";
if (B)cout << B << "B";
//system("pause");
return 0;
}
蓝桥官网全过,洛谷全红