ACM算法练习-——ZJU1164-Software CRC

具体的题目描述点此链接                http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1164

 

这道题,说实话 ,我不懂-.-

我先把这个代码粘在这,具体的这个原因我再研究研究~

 1 #include<stdio.h>
 2 #define Generator 34943
 3 
 4 int main()
 5 {
 6     unsigned char c,flag;
 7     int count;//一行中的字符数
 8     //CRC的数据结构
 9     union
10     {
11         unsigned int L;
12         struct
13         {
14             unsigned char b1;
15             unsigned char b2;
16             unsigned char b3;        
17             unsigned char b4;
18         } crc;
19     }data; 
20     
21     while(1)
22     {
23         count=0;
24         data.L=0;
25         while(scanf("%c",&c)&&c!='\n')
26         {
27             count++;
28             flag=c;
29             data.L=((data.L<<8)+c)%Generator;
30         }
31         
32         data.L=((data.L<<16)+c)%Generator;
33         if(data.L!=0)data.L=Generator-data.L;
34         if(count==1&&flag=='#')break;
35         printf("%02X%02X\n",(int)data.crc.b2,(int)data.crc.b1);
36     }
37     return 0;
38 } 

 

posted @ 2018-08-10 18:16  木&子  阅读(361)  评论(0)    收藏  举报