第十三届JAVAA组决赛——4.内存空间
import java.io.*;
import java.util.*;
public class Main{
public static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
public static PrintWriter stdOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) throws IOException{
int T = Integer.parseInt(stdIn.readLine());
String inStr = null;
long sum = 0;
while(T-- > 0) {
inStr = stdIn.readLine();
int vNum = inStr.split("=").length - 1;
if(inStr.indexOf("[]") == -1) { //属于第一种形式
if(inStr.split(" ")[0].equals("int")) sum += 4L * vNum;
else if(inStr.split(" ")[0].equals("long")) sum += 8L * vNum;
else {
while(vNum-- > 0) {
int startIndex = inStr.indexOf("=");
int endIndex = inStr.indexOf(",");
if(endIndex == -1) endIndex = inStr.indexOf(";");
String subStr = inStr.substring(startIndex+1, endIndex);
if(!subStr.equals("")) sum += subStr.length() - 2L;
inStr = inStr.substring(endIndex + 1);
}
}
}else {//属于第二种形式
int typeSize = 0;
if(inStr.split("/[/]")[0].equals("int")) typeSize = 4;
else typeSize = 8;
while(vNum-- > 0) {
int startIndex = inStr.indexOf("[");
int endIndex = inStr.indexOf("]");
if(startIndex == endIndex - 1) {
vNum++;
inStr = inStr.substring(endIndex + 1);
continue;
}
sum += Integer.parseInt(inStr.substring(startIndex+1, endIndex)) * (long)typeSize;
inStr = inStr.substring(endIndex + 1);
}
}
}
int a = (int)(sum / 1073741824);
int b = (int)(sum % 1073741824 / 1048576);
int c = (int)(sum % 1073741824 % 1048576 / 1024);
int d = (int)(sum % 1073741824 % 1048576 % 1024);
if(a != 0) stdOut.print(a + "GB");
if(b != 0) stdOut.print(b + "MB");
if(c != 0) stdOut.print(c + "KB");
if(d != 0) stdOut.print(d + "B");
stdOut.println();
stdOut.flush();
}
}