Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:比赛结束了,帖个程序吧,请指点

Posted by 0912090002 at 2010-01-16 13:16:52 on Problem 3754
In Reply To:比赛结束了,帖个程序吧,请指点 Posted by:0911300017 at 2010-01-16 12:07:39
> #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;
> }

莫非是楼教主?膜拜一下``
我就是float那里不知道怎么转``查了一下那个IEEE标准,看晕了``原来可以这样弄``长见识了

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator