标签:-- ref 条件 who href ber ica 如何 cond
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 50515 | Accepted: 15808 |
Description
Input
Output
Sample Input
1 ABCD EFGH even ABCI EFJK up ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light.
Source
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 5 #define TRUE (int)1 6 #define FALSE (int)0 7 8 #define CASE_NUM 3 9 #define MAX_COIN_NUM 12 10 11 typedef int BOOL; 12 13 typedef struct 14 { 15 int strLen; 16 char str1[MAX_COIN_NUM+1]; 17 char str2[MAX_COIN_NUM+1]; 18 char delta[5]; 19 }WeightCase; 20 21 WeightCase g_case[CASE_NUM]; 22 BOOL g_isEvenCoin[MAX_COIN_NUM]; 23 char g_coin[MAX_COIN_NUM]; 24 25 const char up[5] = "up\0"; 26 const char down[5] = "down\0"; 27 const char even[5] = "even\0"; 28 29 void Input() 30 { 31 int i = 0; 32 for(i = 0; i < CASE_NUM; i++) 33 { 34 scanf(" %s", g_case[i].str1); 35 scanf(" %s", g_case[i].str2); 36 scanf(" %s", g_case[i].delta); 37 g_case[i].strLen = strlen(g_case[i].str1); 38 } 39 } 40 41 void ProcEvenCase() 42 { 43 int i, j; 44 45 for(i = 0; i < CASE_NUM; i++) 46 { 47 if(0 != strcmp(g_case[i].delta, even)) continue; 48 49 for(j = 0; j < g_case[i].strLen; j++) 50 { 51 g_isEvenCoin[g_case[i].str1[j] - ‘A‘] = TRUE; 52 g_isEvenCoin[g_case[i].str2[j] - ‘A‘] = TRUE; 53 } 54 } 55 } 56 57 void ProcOtherCase() 58 { 59 int i, j, delta; 60 61 for(i = 0; i < CASE_NUM; i++) 62 { 63 if(0 == strcmp(g_case[i].delta, even)) continue; 64 65 if(0 == strcmp(g_case[i].delta, up)) 66 delta = 1; 67 else 68 delta = -1; 69 70 for(j = 0; j < g_case[i].strLen; j++) 71 { 72 if(!g_isEvenCoin[g_case[i].str1[j] - ‘A‘]) g_coin[g_case[i].str1[j] - ‘A‘] += delta; 73 if(!g_isEvenCoin[g_case[i].str2[j] - ‘A‘]) g_coin[g_case[i].str2[j] - ‘A‘] -= delta; 74 } 75 } 76 } 77 78 void Proc() 79 { 80 memset(g_coin, 0, sizeof(g_coin)); 81 memset(g_isEvenCoin, FALSE, sizeof(g_isEvenCoin)); 82 83 ProcEvenCase(); 84 ProcOtherCase(); 85 } 86 87 void Output() 88 { 89 int i, tmp, pos = 0, max = 0; 90 char coin; 91 for(i = 0; i < sizeof(g_coin); i++) 92 { 93 tmp = abs(g_coin[i]); 94 if(tmp > max) 95 { 96 max = tmp; 97 pos = i; 98 } 99 } 100 coin = pos+‘A‘; 101 102 if(g_coin[pos] < 0) 103 printf("%c is the counterfeit coin and it is light.\n", coin); 104 else 105 printf("%c is the counterfeit coin and it is heavy.\n", coin); 106 } 107 108 int main() 109 { 110 int num = 0; 111 scanf("%d", &num); 112 while(num--) 113 { 114 Input(); 115 Proc(); 116 Output(); 117 } 118 119 return 0; 120 }
标签:-- ref 条件 who href ber ica 如何 cond
原文地址:https://www.cnblogs.com/bixiongquan/p/8890869.html