#13149: define真好用


wei115 (unknown)

學校 : 僑光技術學院
編號 : 66295
來源 : [59.126.109.77]
最後登入時間 :
2019-08-07 20:37:49
c081. 00102 - Ecological Bin Packing -- UVa102 | From: [101.139.185.1] | 發表日期 : 2017-12-18 13:14

#include<stdio.h>
#include<string.h>

#define GBC(x, y, z) ((x##2+x##3) + (y##1+y##3) + (z##1+z##2))
#define MIN(x, y, z) do{if(x > y){strcpy(str, z); x = y;}}while(0)

int main()
{
int g1, g2, g3;
int b1, b2, b3;
int c1, c2, c3;

while(scanf("%d%d%d %d%d%d %d%d%d", \
&b1, &g1, &c1, &b2, &g2, &c2, &b3, &g3, &c3) != EOF)
{
int min, reg;
char str[10] = "BCG";

min = GBC(b, c, g);

reg = GBC(b, g, c);
MIN(min, reg, "BGC");

reg = GBC(c, b, g);
MIN(min, reg, "CBG");

reg = GBC(c, g, b);
MIN(min, reg, "CGB");

reg = GBC(g, b, c);
MIN(min, reg, "GBC");

reg = GBC(g, c, b);
MIN(min, reg, "GCB");

printf("%s %d\n", str, min);
}

return 0;
}

話說define 的##原來在C89也能用...

 

 
ZeroJudge Forum