J How Much Memory Your Code Is Using?
字符串模拟
#include<bits/stdc++.h> using namespace std; int main() { //freopen("in.txt","r",stdin); //ios::sync_with_stdio(false),cin.tie(0); int kase=0; int T; cin>>T; while(T--) { int n; int ans=0; int num; cin>>n; getchar(); for(int i=0;i<n;i++) { //getchar(); string s; int tmp; getline(cin,s); //cout<<s<<endl; string str=s; //cout<<str<<endl; if(s[0]=='b')tmp=1; else if(s[0]=='c')tmp=1; else if(s[0]=='i')tmp=4; else if(s[0]=='d')tmp=8; else if(s[0]=='f')tmp=4; else if(s[0]=='_')tmp=16; else if(s[0]=='l') { if(s[5]=='l')tmp=8; else if(s[5]=='d')tmp=16; } int loc1=str.find("["); num=0; if(loc1!=-1) { int loc2=str.find("]"); for(int i=loc1+1;i<loc2;i++) { num=num*10+s[i]-'0'; } } if(num)tmp*=num; ans+=tmp; } ans=ceil((double)ans/1024); cout<<"Case #"<<++kase<<": "<<ans<<endl; } return 0; }