A Digital Satire of Digital Age

兩個天平

判斷兩邊的字母ascall碼值中1的個數是否相等

輸出比較麻煩

我是先根據高低畫出天平   再在天平的倒數第二行放上字母


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RS(s) scanf("%s", s)
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000000;

const int U = 0, Tie = 1, L = 2;
int st1, st2, all1, all2;
char mat[10][20];
vector<char> lef, rig;
const char tp[][10] = {   ".../\\...",
                          "../..\\..",
                          "./....\\.",
                          "/......\\",
                          "\\______/"};

int fun(char c)
{
    int t = (int)c;
    int cnt =0;
    REP(i, 7)
        if (t & (1 << i))
            cnt++;
    return cnt * 500 + (7 - cnt) * 250;
}

bool judge()
{
    if (all1 == all2 && st1 == Tie && st2 == Tie)
        return 1;
    if (all1 > all2 && st1 == L && st2 == U)
        return 1;
    if (all1 < all2 && st1 == U && st2 == L)
        return 1;
    return 0;
}

void dis(int wh, int st) /// 0 Left   1 Right
{
    int s = 0;
    if (wh) s = 10;
    if (st == U)                            ///輕的一邊
    {
        REP(i, 5)
        {
            int ii = 0;
            FE(j, s, s + 7)
                mat[i][j] = tp[i][ii++];
        }
        FE(i, s, s + 7)
            mat[5][i] = mat[6][i] = '.';
        if (wh == 0)                         ///再放字母
        {
            int sz = lef.size();
            REP(i, sz)
                mat[3][i + 1] = lef[i];
        }
        else
        {
            int sz = rig.size();
            REP(i, sz)
                mat[3][11 + i] = rig[i];
        }
    }
    else if (st == Tie)
    {
        FE(i, s, s + 7)
            mat[0][i] = '.';
        FE(i, 1, 5)
        {
            int ii = 0;
            FE(j, s, s + 7)
                mat[i][j] = tp[i - 1][ii++];
        }
        FE(i, s, s + 7)
            mat[6][i] = '.';
        if (wh == 0)
        {
            int sz = lef.size();
            REP(i, sz)
                mat[4][i + 1] = lef[i];
        }
        else
        {
            int sz = rig.size();
            REP(i, sz)
                mat[4][11 + i] = rig[i];
        }
    }
    else
    {
        FE(i, s, s + 7)
            mat[0][i] = mat[1][i] = '.';
         FE(i, 2, 6)
         {
             int ii = 0;
            FE(j, s, s + 7)
                mat[i][j] = tp[i - 2][ii++];
         }
         if (wh == 0)
        {
            int sz = lef.size();
            REP(i, sz)
                mat[5][i + 1] = lef[i];
        }
        else
        {
            int sz = rig.size();
            REP(i, sz)
                mat[5][11 + i] = rig[i];
        }
    }
}

void solve()
{
    all1 = all2 = 0;
    lef.clear(), rig.clear();
    bool f1 = true, f2 = 1;
    REP(i, 7)
    {

        REP(j, 18)
        {
            if (j < 8)
            {
                if (mat[i][j] == '/' && f1)
                    st1 = i, f1 = false;
                if (isalpha(mat[i][j]))
                    all1 += fun(mat[i][j]), lef.push_back(mat[i][j]);
            }
            else if (j >= 10 && j < 18)
            {
                if (mat[i][j] == '/' && f2)
                    st2 = i, f2 = false;
                if (isalpha(mat[i][j]))
                    all2 += fun(mat[i][j]), rig.push_back(mat[i][j]);
            }
        }
    }
    if (judge())
    {
        puts("The figure is correct.");
        return;
    }
    else
    {
        if (all1 > all2)
            dis(0, L), dis(1, U);
        else if (all1 == all2)
            dis(0, Tie), dis(1, Tie);
        else
            dis(0, U), dis(1, L);
        REP(i, 7)
        {
            REP(j, 18)
            cout << mat[i][j];
            cout << endl;
        }
    }
}

int main()
{
    int T, kase = 0;
    RI(T);
    char tmp[20];
    while (T--)
    {
        REP(i, 7)
            RS(mat[i]);
        RS(tmp);
        printf("Case %d:\n", ++kase);
        solve();
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章