//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "表达式求值": {
        "prefix": "acm-2.1加 减 乘 除 幂 括号",
        "body": [
            "#include<iostream>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cctype>",
            "#define LL long long",
            "using namespace std;",
            "int n,f,t1,t2,i,power[300],ch[40];",
            "LL x,sum[40];string a;",
            "LL mi(LL x,LL k){",
            "    LL s=1;",
            "    while(k){",
            "        if(k&1)s=(s*x);",
            "        x=(x*x);k>>=1;",
            "    }",
            "    return s;",
            "}",
            "inline void pop(char fh){",
            "    t1--;t2--;",
            "    if(fh=='+')sum[t1]+=sum[t1+1];",
            "    if(fh=='-')sum[t1]-=sum[t1+1];",
            "    if(fh=='*')sum[t1]*=sum[t1+1];",
            "    if(fh=='/')sum[t1]/=sum[t1+1];",
            "    if(fh=='^')sum[t1]=mi(sum[t1],sum[t1+1]);",
            "}",
            "int main(){",
            "    cin>>a;a='('+a+')';n=a.size();",
            "    power['(']=0;power['+']=power['-']=1;power['*']=power['/']=2;power['^']=3;",
            "    while(i<n){",
            "        x=0,f=0;",
            "        while(isdigit(a[i]))x=x*10+a[i++]-'0',f=1;",
            "        if(f)sum[++t1]=x;",
            "        if(a[i]=='(')ch[++t2]=a[i++];",
            "        if(a[i]==')'){",
            "            while(ch[t2]!='(')pop(ch[t2]);",
            "            i++;t2--;",
            "        }",
            "        if(power[a[i]]){",
            "            if(a[i]=='-'&&a[i-1]=='('){",
            "                x=0,i++;",
            "                while(isdigit(a[i]))x=x*10+a[i++]-'0';",
            "                sum[++t1]=-x;",
            "            }",
            "            else {",
            "                while(power[a[i]]<=power[ch[t2]])pop(ch[t2]);",
            "                ch[++t2]=a[i++];",
            "            }",
            "        }",
            "    }",
            "    while(t2)pop(ch[t2]);",
            "    printf(\"%lld\",sum[1]);",
            "}",
            ""
        ],
        "description": "插入 表达式求值"
    }
}