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. 动态代理CGlib实例

    1.委托类: package 动态代理2; //需要对这个类进行增强 public class UserService { public void create() { System.out.prin ...

  2. HW6.10

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  3. leetcode@ [134] Gas station (Dynamic Programming)

    https://leetcode.com/problems/gas-station/ 题目: There are N gas stations along a circular route, wher ...

  4. POJ3666-Making the Grade(左偏树 or DP)

    左偏树 炒鸡棒的论文<左偏树的特点及其应用> 虽然题目要求比论文多了一个条件,但是……只需要求非递减就可以AC……数据好弱…… 虽然还没想明白为什么,但是应该觉得应该是这样——求非递减用大 ...

  5. 数据结构上机实验dfs&&bfs遍历图

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #inc ...

  6. WinForm中当TextBox重新获得焦点时输入法失效问题

    在winform 中,每当TextBox获得焦点时,部分输入法会失效(如智能ABC.五笔98.极品五笔等),需要重新切换输入法才能正常使用. 此时要将Form的ImeMode属性改为:OnHalf(或 ...

  7. [iOS基础控件 - 1] UI概念

    A. UIView 1.概念      属于UIKit框架      屏幕上能看得见摸得着的东西就是UIView,比如屏幕上的按钮.文字.图片      翻译为:视图/控件/组件      UIBut ...

  8. os7新特性之生成二维码

    先导入CoreImage.framework 生成二维码 读取二维码

  9. MSSQLSERVER数据库- 慎用SELECT INTO复制表

    很多时候我们习惯于用SELECT INTO复制一个表或表结构,因为它方便,快捷,而且在某些情况下效率比INSERT INTO 效率要高一些.但是要注意: SELECT INTO 复制表或表结构的时候, ...

  10. 知方可补不足~SQL数据库用户的克隆,SQL集群的用户同步问题

    我们知道在为sqlserver建立功能数据库时,通过会为库再建立一个登陆名,而这个登陆名时,只用来管理这个数据库,这是安全的,正确的.