Codeforces Beta Round #96 (Div. 2)

來源:互聯網
上載者:User
C. Turing Tapetime limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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:

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.

2. The i-th element of the array is subtracted from the result of the previous step modulo 256.

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.

You are given the text printed using this method. Restore the array used to produce this text.

<p< p="" style="font-family: verdana, arial, sans-serif; font-size: 14px; line-height: 21px; "><p< p="">

Input

<p< p="">

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.

<p< p=""><p< p="">

Output

<p< p="">

Output the initial array, which was used to produce text, one integer per line.

<p< p=""><p< p="">

Sample test(s)

<p< p=""><p< p="">

input
Hello, World!
output
23810811206419448262441682416162

<p< p=""><p< p="">

Note

<p< p="">

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.

  1. #include<iostream>using namespace std;int main(){    char str[200];    int num, i, j, k;    int pre = 0;    char temp[10];    cin.getline(str,200,'\n');    for ( i = 0; str[i] != 0; i++ )    {        num = str[i]; j = 0;        while ( num != 0  )        {            k = num % 2;            temp[j++] = k + '0';            num = ( num - k ) / 2;        }        while ( j < 8 ) temp[j++] = '0';        temp[j] = '\0';        for ( j = 0; j < 8; j++ )            num += (temp[j] -'0') << (7-j) ;        //cout << "##" << temp << ' ' << num << endl;        k = (pre - num ) % 256;        if ( k < 0 ) k += 256;        cout << k << endl;        pre = num;    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.