#include using namespace std; const int N = 1e3 + 10; char mp[N][N]; int s[N], t[N], top; int main() { FILE *fp; fp = fopen("prog.txt", "r"); ///文件读操作 char ch; int tot = 0; int i = 0; while ((ch = fgetc(fp)) != EOF) ///一个字符一个字符的读入 { if (ch == '\n') { mp[tot][i] = '\0'; tot++; i = 0; continue; } mp[tot][i++] = ch; } /* for(int i=0;i= p) ///开始新的循环,上一层的循环不包括 w /= t[top--]; if (mp[i][len - 1] == ':') ///当前是循环语句 { int num = mp[i][len - 2] - '0'; top++; w *= num; ///累计循环了几次 s[top] = p, t[top] = num; ///第top层循环语句的缩进量和循环次数 } else { int num = mp[i][len - 1] - '0'; sum += w * num; } } printf("%d\n", sum); return 0; }