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 (输入字符串并对单个字符进行操作的输入输出)的更多相关文章

  1. UVa 213 Message Decoding(World Finals1991,串)

     Message Decoding  Some message encoding schemes require that an encoded message be sent in two part ...

  2. UVA 213 Message Decoding 【模拟】

    题目链接: https://cn.vjudge.net/problem/UVA-213 https://uva.onlinejudge.org/index.php?option=com_onlinej ...

  3. uva 213 Message Decoding

    思路来自紫书...开始时的思路估计100行+,果断放弃!关键:1.正确提取出函数!   initmap():初始化字母与整数的映射.   returnint(x):向后读取x位,并转换为十进制数返回. ...

  4. 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题

    题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下,  里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...

  5. uva 213 - Message Decoding (我认为我的方法要比书上少非常多代码,不保证好……)

    #include<stdio.h> #include<math.h> #include<string.h> char s[250]; char a[10][250] ...

  6. JS取出特定字符前后的字符串,针对一串字符里面的单个字符前后的字符串

    //针对一串自负里面的单个字符前后的字符串<!doctype html> <html> <head> <meta charset="utf-8&qu ...

  7. uvaoj 213 - Message Decoding(二进制,输入技巧)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. Base64 报错 的解决办法 (Base-64 字符数组或字符串的长度无效。, 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。)

    Base64 报错 的解决办法, 报错如下:1. FormatException: The input is not a valid Base-64 string as it contains a n ...

  9. 利用 Python django 框架 输入汉字,数字,字符,等。。转成二维码!

    利用 Python django 框架 输入汉字,数字,字符,等..转成二维码! 模块必备:Python环境 + pillow  + qrcode 模块 核心代码import qrcode qr = ...

随机推荐

  1. ubuntu无法进入和引导顺序问题解决

    今天上班过来发现ubuntu无法进入,因为里面有N多资料没有备份,当时很是捉急.不过后来都解决了: 背景: easyBCD安装ubuntu14.07和windows7双系统.基本上这一年多一直用ubu ...

  2. 低级错误之Oracle客户端添加数据

    本来可以为空的外键,自己非要写一个无意义的值,导致数据保存失败.

  3. iOS动画实现总结

    在iOS中,动画实现方向有两种,一种是操作UIView的animation方法,另外一种就是核心动画,但到iOS7中,UIView又跟核心动画牵扯在一起. 方式一(利用核心动画添加动画) 核心动画的层 ...

  4. css中文字体unicode对照表

    为什么要使用Unicode编码代替中文字体 在CSS中使用中文字体通常直接设置字体名称,比如设置字体为宋体:font-family:’宋体’:但因此产生的一个问题是,如果默认编码并不是UTF-8,这会 ...

  5. 强烈推荐android studio用的几个插件,androidstudio

    不懂安装studio插件,看参考博文:android stuido插件安装:http://blog.csdn.net/liang5630/article/details/46372447 1.Butt ...

  6. 【21】必须返回对象时,别妄想返回器reference

    1.考虑有理数Rational,有个友元操作符*,返回Rational对象.返回对象,导致临时对象的构造,析构.效率低,因此会想返回方法内局部对象的引用,这种方法不可行.为什么? 2.调用方法是在st ...

  7. CDOJ 1157 数列(seq) 分块+线段树

    数列(seq) Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1157 Desc ...

  8. Qualcomm Web Site For Android Development

    https://www.codeaurora.org/xwiki/bin/QAEP/release https://support.cdmatech.com/login/ https://chipco ...

  9. jquery处理单击和双击事件

    今天做div点击时,需要用到同一div的单击和双击事件,出现问题如下 例子: Html <body> <div id="div_1">单击双击我</d ...

  10. iOS开发——新特性Swift篇&Swift 2.0 异常处理

    Swift 2.0 异常处理 WWDC 2015 宣布了新的 Swift 2.0. 这次重大更新给 Swift 提供了新的异常处理方法.这篇文章会主要围绕这个方面进行讨论. 如何建造异常类型? 在 i ...