zoukankan      html  css  js  c++  java
  • SPOJ 2157 AntiBlot System

    SPOJ_2157

        其实由于解只有一组,可以将machula所在的数看成一整个未知数而不是只将machula看成未知数,这样就可以方便得转化成一个A+B或者A-B的问题了。

    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
    #define MAXD 110
    int right, ans, rn;
    char a[MAXD], b[MAXD], c[MAXD];
    bool machula(char *str)
    {
        int i;
        for(i = 0; str[i]; i ++)
            if(isalpha(str[i]))
                return true;
        return false;
    }
    void solve()
    {
        int x, y;
        char op[5];
        scanf("%s", a);
        scanf("%s", op);
        scanf("%s", b);
        scanf("%s", op);
        scanf("%s", c);
        if(machula(a))
        {
            sscanf(b, "%d", &x), sscanf(c, "%d", &y);
            ans = y - x;
            printf("%d + %s = %s\n", ans, b, c);
        }
        else if(machula(b))
        {
            sscanf(a, "%d", &x), sscanf(c, "%d", &y);
            ans = y - x;
            printf("%s + %d = %s\n", a, ans, c);
        }
        else
        {
            sscanf(a, "%d", &x), sscanf(b, "%d", &y);
            ans = x + y;
            printf("%s + %s = %d\n", a, b, ans);
        }
    }
    int main()
    {
        int t;
        scanf("%d", &t);
        while(t --)
            solve();
        return 0;
    }
  • 相关阅读:
    「SPOJ10707」Count on a tree II
    UVA 11021 /概率
    power oj/2360/Change
    POJ1613 147/思维题
    Power oj2498/DP/递推
    HDU4815/计数DP
    444A/CF
    观光公交noip<贪心>
    2014 Shanghai Invitation Contest
    POJ1734/Floyd求最小环
  • 原文地址:https://www.cnblogs.com/staginner/p/2574038.html
Copyright © 2011-2022 走看看