UVA - 213 Message Decoding (输入字符串并对单个字符进行操作的输入输出)
POINT:
关于表示一个编码:利用code字符数组表示一个编码字符,其中code[len][val]表示长度为len,二进制值为val的字符;
主程序如下:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip> using namespace std;
#define INF 0x7fffffff
#define maxn 1010
typedef unsigned long long ull; int code[][<<]; int main()
{
while(readcodes())
{
//printcodes();
for(;;)
{
int len = readint();
if(len == ) break;
//printf("len = %d\n", len); for(;;)
{
int v = readint(len);
//printf("v = %d\n", v);
if(v == (<<len)-) break;
putchar(code[len][v]);
}
}
putchar('\n');
}
return ;
}
其中readcodes()函数用来读取编号,readint()函数用来读取c位二进制字符并转化为整数(val);
如何处理“编码文本可由多行组成”
bool readcodes()
{
memset(code, , sizeof(code));//清空数组
code[][] = readchar();//输入开始;单个字符输入
for(int len = ; len <= ; len++)
{
for(int val = ; val < (<<len)-; val++)
{
int ch = getchar();
if(ch == EOF) return ;
if(ch == '\n' || ch == '\r') return ; code[len][val] = ch;
}
}
return ;
}
int readint(int c)
{
int v = ;
while(c--)
v = v*+readchar()-'';
return v;
}
readchar()函数代码如下:
int readchar()
{
for(;;)
{
int ch = getchar();
if(ch != '\n' && ch != '\t') return ch;
}
}
另外,Printcodes()函数本身对题目没有要求,但是对于调试代码是有用的。
UVA - 213 Message Decoding (输入字符串并对单个字符进行操作的输入输出)的更多相关文章
- UVa 213 Message Decoding(World Finals1991,串)
Message Decoding Some message encoding schemes require that an encoded message be sent in two part ...
- UVA 213 Message Decoding 【模拟】
题目链接: https://cn.vjudge.net/problem/UVA-213 https://uva.onlinejudge.org/index.php?option=com_onlinej ...
- uva 213 Message Decoding
思路来自紫书...开始时的思路估计100行+,果断放弃!关键:1.正确提取出函数! initmap():初始化字母与整数的映射. returnint(x):向后读取x位,并转换为十进制数返回. ...
- 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题
题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下, 里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...
- uva 213 - Message Decoding (我认为我的方法要比书上少非常多代码,不保证好……)
#include<stdio.h> #include<math.h> #include<string.h> char s[250]; char a[10][250] ...
- JS取出特定字符前后的字符串,针对一串字符里面的单个字符前后的字符串
//针对一串自负里面的单个字符前后的字符串<!doctype html> <html> <head> <meta charset="utf-8&qu ...
- uvaoj 213 - Message Decoding(二进制,输入技巧)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Base64 报错 的解决办法 (Base-64 字符数组或字符串的长度无效。, 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。)
Base64 报错 的解决办法, 报错如下:1. FormatException: The input is not a valid Base-64 string as it contains a n ...
- 利用 Python django 框架 输入汉字,数字,字符,等。。转成二维码!
利用 Python django 框架 输入汉字,数字,字符,等..转成二维码! 模块必备:Python环境 + pillow + qrcode 模块 核心代码import qrcode qr = ...
随机推荐
- POJ 3321 Apple Tree(dfs序树状数组)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=10486 题意:一颗有n个分支的苹果树,根为1,每个分支只有一个苹果,给出n- ...
- Code First 更新数据库结构
参考:http://blog.csdn.net/sxycxwb/article/details/12186159 0.删除之前的数据库 1.Run the Enable-Migrations comm ...
- mysql修改字段的语句写法
http://www.111cn.net/database/mysql/50678.htm 下面为您介绍的sql语句都是mysql修改字段操作中的一些常用语句,如果您是一个刚刚接触mysql数据库的新 ...
- Timeout Detection & Recovery (TDR)
Timeout Detection & Recovery (TDR) NVIDIA® Nsight™ Development Platform, Visual Studio Edition 2 ...
- nodejs学习:师哥自家的twenty博客框架
这周继续为DTree项目预热,学习sails框架的搭建和结构熟悉.正好师哥在做一个nodejs的CMS框架twenty,他们用的就是sails框架. 结构 首先简单了解一下结构.在jade文件里由an ...
- hdoj 2098 分拆素数和
分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdoj 2046 骨牌铺方格
骨牌铺方格 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- ALM11用例测试类型
默认一般都是选择的是manual
- SQL Server里一些未公开的扩展存储过程
SQL Server里一些未公开的扩展存储过程 [转帖] 博客天地 www.inbaidu.com SQL Server里一些未公开的扩展存储过程 扩展存储过程(xp)是直接运行在SQL Server ...
- 逻辑网络(Logical Network)
Introduction The VMM documentation indicates that “A logical network is used to organize and simplif ...