CodeForces 132A Turing Tape

来源:互联网 发布:大数据反洗钱 编辑:程序博客网 时间:2024/05/18 02:05
A. Turing Tape
time 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. Processingi-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 thei-th character to be printed.

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

Input

The input will consist of a single line text which contains the message printed using the described method. Stringtext will contain between 1 and 100 characters, inclusive. ASCII-code of each character oftext will be between 32 (space) and 126 (tilde), inclusive.

Output

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

Sample test(s)
Input
Hello, World!
Output
23810811206419448262441682416162
Note

Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code72 = 010010002. Its reverse is000100102 = 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, wherea mod b is the remainder of division ofa by b.


gets(str+1);     指向字符数组的指针gets(str+1)表示从控制台输入一个字串,放入str+1位置


#include<cstdio>#include<cstring>#include<iostream>using namespace std;int main(){    char c[1200];    int i,j,x,y,len,lans;gets(c+1);      len=strlen(c+1);lans=0;for(i=1;i<=len;i++){x=c[i];y=0;for(j=1;j<=8;j++){   //求ASCII码的8位2进制倒数的十进制y=y*2+x%2;x/=2;}cout<<(lans-y+256)%256<<endl;lans=y;}}



0 0
原创粉丝点击