題目連結: https://zerojudge.tw/ShowProblem?problemid=c093

# 解題思路

數據小,直接窮舉可能的 24 種答案,看那一組符合秤重結果!!

# 程式碼

#include<stdio.h>
#include<string.h>
struct record {
	char l[13], r[13], st[4];
}D[3];
main() {
    int t, a, b, c, suml, sumr;
    scanf("%d", &t);
    while(t--) {
        for(a = 0; a < 3; a++)
            scanf("%s %s %s", &D[a].l, &D[a].r, &D[a].st);
        for(a = 0; a < 12; a++) {
            for(b = 0; b < 3; b++) {
                suml = 0, sumr = 0;
                for(c = 0; D[b].l[c]; c++)
                    suml += (D[b].l[c] - 'A' != a);
                for(c = 0; D[b].r[c]; c++)
                    sumr += (D[b].r[c] - 'A' != a);
                if(suml == sumr && D[b].st[0] == 'e') continue;
                if(suml < sumr && D[b].st[0] == 'd') continue;
                if(suml > sumr && D[b].st[0] == 'u') continue;
                break;
            }
            if(b == 3)	break;
        }
        if(a != 12)
            printf("%c is the counterfeit coin and it is light.\n", a + 'A');
        for(a = 0; a < 12; a++) {
            for(b = 0; b < 3; b++) {
                suml = 0, sumr = 0;
                for(c = 0; D[b].l[c]; c++)
                    suml += (D[b].l[c] - 'A' == a);
                for(c = 0; D[b].r[c]; c++)
                    sumr += (D[b].r[c] - 'A' == a);
                if(suml == sumr && D[b].st[0] == 'e') continue;
                if(suml < sumr && D[b].st[0] == 'd') continue;
                if(suml > sumr && D[b].st[0] == 'u') continue;
                break;
            }
            if(b == 3)	break;
        }
        if(a != 12)
            printf("%c is the counterfeit coin and it is heavy.\n", a + 'A');
    }
    return 0;
}
更新於 閱讀次數

用實際行動犒賞爆肝的我😀

Zrn Ye LinePay

LinePay