Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
比赛结束了,帖个程序吧,请指点In Reply To:编译器疑问C vs GCC Posted by:0911300017 at 2010-01-16 11:01:40 #include <stdio.h> char getChar(int v) { if (v < 10) return (char)('0' + v); else return (char)('A' + v - 10); } int getValue(char c) { if (c >= '0' && c <= '9') return c - '0'; else if (c >= 'A' && c <= 'Z') return c - 'A' + 10; else return c - 'a' + 10; } char str[100]; int A[4]; int B[8]; int main() { while (scanf("%d,%d,%d,%d", &A[0], &A[1], &A[2], &A[3]) != -1) { int i, j, r, exp; B[0] = A[0]; B[1] = A[1]; B[2] = A[2] >> 8; B[3] = A[2] & 255; B[4] = A[3] >> 8; B[5] = A[3] & 255; r = 0xffff; for (i = 0; i < 6; i++) { r ^= B[i]; for (j = 0; j < 8; j++) if (r&1) r = (r >> 1) ^ 0xa001; else r >>= 1; } r = (r >> 8) + ((r & 255) << 8); B[6] = r >> 8; B[7] = r & 255; for (i = 0; i < 8; i++) printf("%c%c", getChar(B[i] >> 4), getChar(B[i] & 15)); printf("\n"); scanf("%s",str); r = 0xffff; for (i = 0; str[i + 4]; i += 2) { int value = (getValue(str[i]) << 4) + getValue(str[i + 1]); r ^= value; for (j = 0; j < 8; j++) if (r & 1) r = (r >> 1) ^ 0xa001; else r >>= 1; } r = (r >> 8) + ((r & 255) << 8); exp = ((getValue(str[i]) * 16 + getValue(str[i + 1])) * 16 + getValue(str[i + 2])) * 16 + getValue(str[i + 3]); if (r != exp) { printf("CRC_ERROR\n"); } else { for (i = 6; str[i + 4]; i += 8) { int k; unsigned int value = 0; unsigned int *p; float *q; for (k = 0; k < 8; k++) value = (value << 4) + (unsigned int)(getValue(str[i + k])); p = &value; q = (float*)p; if (i > 6) printf(","); printf("%.1lf", (*q)); } printf("\n"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator