#include #include #include int main() { char decl[100],TYPE[15] , SIGN[15] , VAR[20] , *token ; int TYPE_SIZE = 0 , total_size = 0, i , ARRAY_SIZE = 1 , value , array_f = 0; while(1) { fgets(decl,sizeof(decl),stdin); sscanf(decl,"%s %s",TYPE,VAR); TYPE_SIZE = 0; total_size = 0; if(strcmp(TYPE,"char") == 0) TYPE_SIZE = 1; if(strcmp(TYPE,"short") == 0) TYPE_SIZE = 2; if(strcmp(TYPE,"int") == 0) TYPE_SIZE = 4; if(strcmp(TYPE,"unsigned") == 0) { sscanf(decl," %s %s %s",SIGN,TYPE,VAR); if(strcmp(TYPE,"char") == 0) TYPE_SIZE = 1; if(strcmp(TYPE,"short") == 0) TYPE_SIZE = 2; if(strcmp(TYPE,"int") == 0) TYPE_SIZE = 4; } token = strtok(VAR,","); while(token != NULL) { ARRAY_SIZE = 1; i = 0; array_f = 0; while(token[i] != '\0') { if(token[i] == '[') { i++; array_f = 1; value = 0; while(token[i] != ']') { value = value * 10 + (token[i] - '0'); i++; } ARRAY_SIZE = ARRAY_SIZE * value; } i++; } if(array_f == 1) { total_size = total_size + ARRAY_SIZE * TYPE_SIZE; } else { total_size = total_size + TYPE_SIZE; } token = strtok(NULL,","); } if(TYPE_SIZE == 0) break; else { printf("%d\n",total_size); } memset(TYPE,0,sizeof(TYPE)); } return 0; }