xdm 求hack
查看原帖
xdm 求hack
877860
Just_Love_You楼主2023/8/6 19:57
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
constexpr int N=1e5+10;
constexpr int mod=1e9+7;
void solve()
{
    string s;
    cin >> s;
    int up=0;
    int down=0;
    int tmp=0;
    int l=0;
    int r=0;
    bool v=true;
    if(s[0]=='-')
        v=false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]>='0'&&s[i]<='9')
        {
            tmp*=10;
            tmp+=s[i]-'0';
        }
        if(s[i]=='/')
        {
            l=tmp;
            tmp=0;
        }
        if((s[i]=='+'||s[i]=='-'||i==s.size()-1)&&i!=0)
        {
            r=tmp;
            tmp=0;
            if(v)
            {
                if(up&&down)
                {
                    up=up*r/__gcd(down,r);
                    l=l*down/__gcd(down,r);
                    up+=l;
                    down=down/__gcd(down,r)*r;
                }else
                {
                    up=l;
                    down=r;
                }
            }else{
                    if(up&&down)
                    {
                        up=up*r/__gcd(down,r);
                        l=l*down/__gcd(down,r);
                        up-=l;
                        down=down/__gcd(down,r)*r;
                    }else
                    {
                        up=-l;
                        down=r;
                    }
            }
            if(s[i]=='+')
                v=true;
            else v=false;
            r=0;
            l=0;
            int p=__gcd(up,down);
            up/=p;
            down/=p;
        }
    }
    if(down==1)
        cout << up;
    else if(up==0)
        cout << 0;
    else
    cout << up << '/' << down;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // int o;
    // cin >> o;
    // while(o--)
    solve();
    return 0;
}
//
//⠀⠀⠀             ⠀⢸⣿⣿⣿⠀⣼⣿⣿⣦⡀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀ ⠀⢸⣿⣿⡟⢰⣿⣿⣿⠟⠁
//⠀⠀⠀⠀⠀⠀⠀⢰⣿⠿⢿⣦⣀⠀⠘⠛⠛⠃⠸⠿⠟⣫⣴⣶⣾⡆⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠉⢿⣦⡀⠀⠀⠀⠀⠀⠀⠛⠿⠿⣿⠃⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣦⠀⠀⠹⣿⣶⡾⠛⠛⢷⣦⣄⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠈⠉⣀⡀⠀⠀⠙⢿⡇
//⠀⠀⠀⠀⠀⠀⢀⣠⣴⡿⠟⠋⠀⠀⢠⣾⠟⠃⠀⠀⠀⢸⣿⡆
//⠀⠀⠀⢀⣠⣶⡿⠛⠉⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⢸⣿⠇
//⢀⣠⣾⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⢀⣼⣧⣀⠀⠀⠀⢀⣼⠇ 
//⠈⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠋⠙⠛⠛⠛⠛⠛⠁
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⡿⠋⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⢾⠿⠋⠀
//
2023/8/6 19:57
加载中...