next up previous
Next: Sequence of Differences Up: No Title Previous: No Title

Computer Networks

You are designing a computer network to control trading on the international currency market. Because hundreds of millions of dollars, euros, and yen are being traded each day, you must ensure that data is transmitted correctly between computers.

One technique for ensuring data is being transmitted correctly is to compute and send a checksum, a small integer value representing the data transmitted. The receiving computer can then also compute its own checksum. If the checksums match, the data is probably correct. The IP (internet protocol) algorithm for computing a checksum is treat the data as a series of 16-bit numbers, add the numbers using one's complement arithmetic, then take the one's complement of the result.

In your network, data is being sent in packets of four 8-bit numbers (i.e., numbers between 0 and 255). The fourth number in each packet is a checksum for the packet. Your job is to compute a 8-bit checksum for each packet and verify the packet is correct. You can compute a checksum as follows:

  1. Calculate X, the sum of the first three 8-bit numbers in the packet.
  2. While tex2html_wrap_inline420 , subtract 256 from X.
  3. Subtract X from 255.

The resulting value for X should be a 8-bit number. Compare the checksum calculated with the checksum transmitted in each packet to verify transmission worked properly. Print out a warning for invalid data packets so the currency traders can resend data. The fate of the world economy is in your hands, so be careful!

Input Format

The input will consist of a number of packets, each on a separate line. Each packet will consist of four 8-bit numbers, where the fourth number is the checksum transmitted. The list of packets will be terminated by a line containing only -1.

Output Format

For each packet, output "valid" or "invalid".



0 0 0 255
1 2 3 249
100 20 35 100
10 12 14 200
200 100 200 11



Test data used in judging

Input 1 Output 1
Input 2 Output 2
Input 3 Output 3

Our Solution

next up previous
Next: Sequence of Differences Up: No Title Previous: No Title

Chau-Wen Tseng
Mon Mar 15 13:58:05 EST 1999