Ultraviolet A 128-Software CRC

Source: Internet
Author: User

The meaning of the question is hard to understand. Simply put, we will give you a string. Each character occupies one byte (in December 256), followed by two more bytes, so that the total value of the string can be fully divided by 34943, finally, the hexadecimal values of the two characters are output.

The Code is as follows:

# Include <cstdio> # include <cmath> # include <cstring> char str [1030]; const int MAX = 34943; int main () {# ifdef test freopen ("sample.txt", "r", stdin); # endif int len; char s [5]; while (gets (str )) {if (str [0] = '#') break; len = strlen (str); if (! Len) {printf ("00 00 \ n"); continue;} long ans = 0; for (int I = 0; I <len; I ++) ans = (ans <8) + str [I]) % MAX; ans = (ans <16) % MAX; // the number to be added is 34943-ans, then convert to hexadecimal; ans = MAX-ans; for (int I = 3; I> = 0; I --) {int res = ans % 16; if (res <10) s [I] = res + '0'; else s [I] = res-10 + 'a'; ans/= 16 ;} printf ("% c \ n", s [0], s [1], s [2], s [3]);} return 0 ;}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.