CodeForces 132A Turing Tape
来源:互联网 发布:大数据反洗钱 编辑:程序博客网 时间:2024/05/18 02:05
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.
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 the initial array, which was used to produce text, one integer per line.
Hello, World!
23810811206419448262441682416162
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;}}
- CodeForces 132A Turing Tape
- A Turing-complete language: Brainf*ck
- PTM-A Parallel Turing Machine Protocol
- COMPUTING MACHINERY AND INTELLIGENCE -- BY A.M.TURING
- 格式化数据#2:图灵奖(A.M. Turing Award)
- CodeForces-a
- Ticker Tape
- TGT + TAPE
- Codeforces 903A A
- Turing机
- Turing Award
- Turing equation
- Turing equation
- Turing equation
- Turing equation
- Codeforces Round #132 (Div. 2) A题
- ACM Names Barbara Liskov Recipient of the 2008 ACM A.M. Turing Award
- CodeForces 18A A - Triangle
- POJ--2431 Expedition
- Android实现SwipeBack(右滑退出)效果
- 用Qt实现一个桌面弹幕程序(六)-- -- 桌面客户端实现②
- 元素的 tabIndex 属性
- LeetCode 104. Maximum Depth of Binary Tree
- CodeForces 132A Turing Tape
- Python笔记
- 《推荐系统实践》二刷开始,顺便做个规划
- 实时数据库简介和比较---PI
- 删除MySql服务
- 冒泡的排序,原来如此
- HDU 1176(二维动态规划)
- 图像基本变换
- 信息提醒之Notification,兼容全部SDK-更新中