[网页工具] C++压行

[网页工具] C++压行

将C++的代码压进最少的行数,增加不可读性,抄代码必备。


 

评论: 1

  1. 叶ID说道:

    Before

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    ll parseLl(string v)
    {
        ll egg=0;
        for(int i=int(-4)+(int)v.length();i<(int)v.length();i++)
        {
            if(i>=0) egg=egg*10+(v[i]-'0');
        }
        return egg;
    }
    
    stack<ll> numstack;
    stack<bool> symstack;  //TRUE=*, FALSE=+
    vector<string> tokens;
    int main()
    {
        ios::sync_with_stdio(false);
        string exp;
        getline(cin,exp);
    
        /* Parse tokens */
        {
            int l=0;
            bool c=1;  //TRUE=num, FALSE=sym
            for(unsigned i=1;i<exp.length();i++)
            {
                if(isdigit(exp[i])^c)
                {
                    tokens.push_back(exp.substr(l,i-l));
                    c=isdigit(exp[i]);
                    l=i;
                }
            }
            tokens.push_back(exp.substr(l,exp.length()-l));
        }
    
        for(unsigned i=0;i<tokens.size();i++)
        {
            //cout<<"Current token is "<<tokens[i]<<endl;
            bool isnum=isdigit(tokens[i][0]);
            if(isnum)
            {
                numstack.push(parseLl(tokens[i]));
                //cout<<"  Pushed as a number:"<<numstack.top()<<endl;
            }
    
            else
            {
                while(!symstack.empty() && symstack.top()>=(tokens[i]=="*"))
                {
                    ll a=numstack.top();
                    numstack.pop();
                    ll b=numstack.top();
                    bool s=symstack.top();
                    numstack.pop();symstack.pop();
                    if(s) numstack.push((a*b)%10000);
                    else numstack.push((a+b)%10000);
                    //cout<<"  Solved:"<<a<<" "<<s<<" "<<b<<endl;
                }
                symstack.push(tokens[i]=="*");
                //cout<<"  Pushed as a symbol:"<<symstack.top()<<endl;
            }
        }
        while(!symstack.empty())
        {
            ll a=numstack.top();
            numstack.pop();
            ll b=numstack.top();
            bool s=symstack.top();
            numstack.pop();symstack.pop();
            if(s) numstack.push((a*b)%10000);
            else numstack.push((a+b)%10000);
            //cout<<"- Last calculated:"<<a<<" "<<s<<" "<<b<<endl;
        }
    
        cout<<numstack.top()<<endl;
    }
    

    After

    #include<bits/stdc++.h>
    using namespace std;typedef long long ll;ll parseLl(string v){ll egg=0;for(int i=int(-4)+(int)v.length();i<(int)v.length();i++){if(i>=0) egg=egg*10+(v[i]-'0');}return egg;}stack<ll> numstack;stack<bool> symstack;  vector<string> tokens;int main(){ios::sync_with_stdio(false);string exp;getline(cin,exp);/* Parse tokens */{int l=0;bool c=1;  for(unsigned i=1;i<exp.length();i++){if(isdigit(exp[i])^c){tokens.push_back(exp.substr(l,i-l));c=isdigit(exp[i]);l=i;}}tokens.push_back(exp.substr(l,exp.length()-l));}for(unsigned i=0;i<tokens.size();i++){bool isnum=isdigit(tokens[i][0]);if(isnum){numstack.push(parseLl(tokens[i]));}else{while(!symstack.empty() && symstack.top()>=(tokens[i]=="*")){ll a=numstack.top();numstack.pop();ll b=numstack.top();bool s=symstack.top();numstack.pop();symstack.pop();if(s) numstack.push((a*b)%10000);else numstack.push((a+b)%10000);}symstack.push(tokens[i]=="*");}}while(!symstack.empty()){ll a=numstack.top();numstack.pop();ll b=numstack.top();bool s=symstack.top();numstack.pop();symstack.pop();if(s) numstack.push((a*b)%10000);else numstack.push((a+b)%10000);}cout<<numstack.top()<<endl;}
    

添加评论

我们将在300年后停止对游客评论的支持。请尽快注册或登录
本站现已支持评论使用Markdown来发挥个性。Markdown说明