codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

132A.md (2039B)


      1 Source: https://codeforces.com/problemset/problem/132/A
      2 
      3 A. Turing Tape
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.
     22 
     23 The integers of the array are processed one by one, starting from the first. Processing *i*-th element of the array is done in three steps:
     24 
     25 1. The 8-bit binary notation of the ASCII-code of the previous printed character is reversed. When the first element of the array is processed, the result of this step is considered to be 0.
     26 
     27 2. The *i*-th element of the array is subtracted from the result of the previous step modulo 256.
     28 
     29 3. The binary notation of the result of the previous step is reversed again to produce ASCII-code of the *i*-th character to be printed.
     30 
     31 You are given the text printed using this method. Restore the array used to produce this text.
     32 
     33 Input
     34 
     35 The input will consist of a single line *text* which contains the message printed using the described method. String *text* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *text* will be between 32 (space) and 126 (tilde), inclusive.
     36 
     37 Output
     38 
     39 Output the initial array, which was used to produce *text*, one integer per line.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 Hello, World!
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 238  
     53 108  
     54 112  
     55 0  
     56 64  
     57 194  
     58 48  
     59 26  
     60 244  
     61 168  
     62 24  
     63 16  
     64 162
     65 ```
     66 
     67 Note
     68 
     69 Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 010010002. Its reverse is 000100102 = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to be (0 - 18) mod 256 = 238, where *a* mod *b* is the remainder of division of *a* by *b*.