Question: there is an existing encoding. When the Shift key is down or up, it corresponds to two types of encoding, two of which correspond to the shift operation.
Returns the corresponding encoding value to the string.
Analysis: analog, String. Simple question: Mark shift for classification.
Note: If the data volume is small, scan and query the data directly.
#include <iostream>#include <cstdlib>#include <string>#include <cstdio>using namespace std;#define down 1#define up 0string ushift,dshift,buf;int code(int space){int value = 0;for (int i = 0 ; i < 5 ; ++ i) {value <<= 1;value += buf[space+i]-'0';}return value;}int main(){getline(cin, dshift);getline(cin, ushift);while (getline(cin, buf)) {int state = down;for (int i = 0 ; i < buf.length() ; i += 5) {int value = code(i);if (value == 27) {state = down;}else if (value == 31) {state = up;}else if (state == down)cout << dshift[value];else cout << ushift[value];}cout << endl;}return 0;}
Ultraviolet A 740-Baudot Data Communication Code