UVa 740 - Baudot Data Communication Code

题目:现有一种编码,他们在shift键处于按下和升起时,对应两种编码,其中有2个编码对应shift操作。

给你对应的编码值,求其对应的字符串。

分析:模拟,字符串。简单题,标记shift的升降分类处理即可。

说明:数据量较小,直接扫描查询即可。

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>

using namespace std;

#define down 1
#define up   0

string 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;
}
时间: 2024-10-06 00:53:37

UVa 740 - Baudot Data Communication Code的相关文章

UVA 12436-Rip Van Winkle&#39;s Code(线段树的区间更新)

题意: long long data[250001]; void A( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = data[i] + (i - st + 1); } void B( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = data[i] + (nd - i + 1); } void C( int st, int nd, int x

matlab路径操作实战(真正实现data和code分离)

假设data文件夹和work文件夹并列,我的所有数据存放于data文件夹里面,我的代码存放于code文件夹里面 1.在code文件夹里面写代码获取data文件夹下所有文件 mainpath=mfilename('fullpath'); index=strfind(mainpath,'\'); mainpath=[mainpath(1:index(end-1)) 'data\'] filename=dir([mainpath '*']); 2.mkdir.save和load函数的高级运用 % 接上

UVa 11754 (中国剩余定理 枚举) Code Feat

如果直接枚举的话,枚举量为k1 * k2 *...* kc 根据枚举量的不同,有两种解法. 枚举量不是太大的话,比如不超过1e4,可以枚举每个集合中的余数Yi,然后用中国剩余定理求解.解的个数不够S个的时候,要把这些解分别加上M.2M...(M = X1 * X2 *...* Xc) 如果上述枚举量太大的话,直接枚举x.找一个k/X最小的条件,然后让x = t * X + Yi开始枚举,因为这样枚举x增长得最快,所以枚举次数也就最少.如果符合要求的话则输出. 上面两种方法都要注意所找到的解为正整

转载:Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005

https://support.microsoft.com/en-us/kb/904803 Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005 Email Print SYMPTOMS Consider the following scenario: In

Linking code for an enhanced application binary interface (ABI) with decode time instruction optimization

A code sequence made up multiple instructions and specifying an offset from a base address is identified in an object file. The offset from the base address corresponds to an offset location in a memory configured for storing an address of a variable

Data analysis system

A data analysis system, particularly, a system capable of efficiently analyzing big data is provided. The data analysis system includes an analyst server, at least one data storage unit, a client terminal independent of the analyst server, and a cach

UVa 112 树求和

题意:给定一个数字,以及一个描述树的字符序列,问存不存在一条从根到某叶子结点的路径使得其和等于那个数.难点在于如何处理字符序列,因为字符间可能有空格.换行等. 思路:本来想着用scanf的(后发现scanf貌似不能做),感觉太麻烦,想看网上有没有处理比较好的,一搜全是用C++的cin流的~  还是自己用C写了一下.用的getchar().getchar()主要就是比较繁琐,需要一个一个字符比较,记得刚开始做字符串题目时比较喜欢用getchar(),有的用scanf就行的自己也喜欢用getchar

6kyu Decode the Morse code

题目: Part of Series 1/3 This kata is part of a series on the Morse code. After you solve this kata, you may move to the next one. 系列的一部分,1/3 这个形是莫尔斯电码系列的一部分.当你解决了这个问题后,你可能会转到下一个.In this kata you have to write a simple Morse code decoder. While the Mor

Method for address space layout randomization in execute-in-place code

The present application relates generally to laying out?address?space for execute-in-place code and, more specifically, to a method for address?space?layout?randomization?for such code. Ahead of executing a program, executable code for which is store