문제 |
아래 링크를 통해 문제를 확인할 수 있습니다.
http://www.jungol.co.kr/prog/Hanal/hanalView.php?qs_code=1239&qlevel=4&sk=&sv=&menu=&qc=44&sst=qs_code&sod=asc&page=1
주의할 점 |
소스 코드 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | #include <stdio.h> #pragma warning(disable:4996) int t, failcnt = 0; char A[] = { '\0', '0', '0', '0', '0', '0', '0' }; char B[] = { '\0', '0', '0', '1', '1', '1', '1' }; char C[] = { '\0', '0', '1', '0', '0', '1', '1' }; char D[] = { '\0', '0', '1', '1', '1', '0', '0' }; char E[] = { '\0', '1', '0', '0', '1', '1', '0' }; char F[] = { '\0', '1', '0', '1', '0', '0', '1' }; char G[] = { '\0', '1', '1', '0', '1', '0', '1' }; char H[] = { '\0', '1', '1', '1', '0', '1', '0' }; char input[70]; char character[11]; int check(); int main() { FILE* fin = fopen("input.txt", "rt"); FILE* fout = fopen("output.txt", "wt"); fscanf(fin, "%d ", &t); fscanf(fin, "%s", &input[1]); if (!check()) { for (int i = 1; i <= t; i++) { if (character[i] == '\0') break; printf("%c", character[i]); fprintf(fout, "%c", character[i]); } printf("\n"); fprintf(fout, "\n"); } else { printf("%d\n", failcnt); fprintf(fout, "%d\n", failcnt); } return 0; } int check() { int failNumber = 0, cnt_tmp = 0, cnt_idx = 1; for (int i = 1; i <= (t * 6);) { failcnt++; // A cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (A[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'A'; i += 6; continue; } if (cnt_tmp >= 2) failNumber = i; // B cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (B[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'B'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // C cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (C[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'C'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // D cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (D[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'D'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // E cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (E[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'E'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // F cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (F[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'F'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // G cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (G[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'G'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // H cnt_tmp = 0; for (int j = i, k = 1; j <= i + 6, k <= 6; j++, k++) { if (H[k] != input[j]) cnt_tmp++; } if (cnt_tmp <= 1) { character[cnt_idx++] = 'H'; i += 6; continue; } if (cnt_tmp >= 2 && failNumber == 0) failNumber = i; // 다왔는데도 못찾으면 if (failNumber != 0) return failcnt; i += 6; } return 0; } |
'Algorithm > 정보올림피아드' 카테고리의 다른 글
알고리즘 > BFS > 저글링 방사능 오염(1078) (0) | 2014.08.28 |
---|---|
알고리즘 > 자료구조A > 불쾌한날(1141) (0) | 2014.08.27 |
알고리즘 > 자료구조A > 빌딩(1328) (0) | 2014.08.21 |
알고리즘 > 자료구조A > 히스토그램(1214) (0) | 2014.08.21 |
실력키우기 > 자료처리 > 이진탐색 (0) | 2014.04.15 |