【例题 4-4 uva 213】Message Decoding
2024-10-01 07:02:26
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
输入的二进制长度最长为7
所以得开个sta[7][2^7]的样子才存的下所有的字符的。。
定义这么一个数组当字典。
然后一个字符一个字符地读。。组合成题目中的参数。
然后根据读入的每个长度为len的二进制,在字典中找到相应的字符就ok啦。
【代码】
#include <bits/stdc++.h>
using namespace std;
string s;
char dic[100][100];
int readbinary(){
char key = cin.get();
while (key!='0' && key!='1') key=cin.get();
return (int)(key-'0');
}
int main()
{
//freopen("/home/ccy/rush.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0);
while (getline(cin,s)){
int cur = 2,now = 0,curlen = 1;
for (int i = 0;i < (int)s.size();i++){
if (now==cur-1) {
now = 0,cur*=2;curlen++;
}
dic[curlen][now] = s[i];
now++;
}
int len = 1;
while (len!=0){
len = 0;
for (int i = 0;i < 3;i++) {
int ju = readbinary();
len = len*2 + ju;
}
int over = 0;
while (1){
over = 1;
int temp = 0;
for (int i = 0;i < len;i++){
int ju = readbinary();
if (ju==0) over = 0;
temp = temp*2+ju;
}
if (over) break;
cout<<dic[len][temp];
}
}
cout<<endl;
cin.get();
}
return 0;
}
最新文章
- Python 6 —— 异常
- 深入浅出设计模式——策略模式(Strategy Pattern)
- Android开发之 Android 的基本组件的概述
- Could not create the view: An unexpected exception was thrown.如何解决
- 28个你必须知道的HTML5的新特性,技巧以及技术
- bzoj 3165: [Heoi2013]Segment 动态凸壳
- 关于标准C语言的预定义宏
- 【LeetCode练习题】Merge Sorted Array
- crm使用soap删除实体
- POJ 1654 Area
- C# dev gridcontrol中添加checkbox复选框
- Go - concurrency
- Toxophily
- 06_java 时间获取练习_Date\SimpleDateFormat\Calendar类练习
- easyui datagrid 横向滚动条
- SpringMVC加载配置Properties文件的几种方式
- mysql笔记-索引
- CF 554A 字符串水题
- Tomcat --> Cannot create a server using the selected type
- flex弹性布局属性详解!
热门文章
- 学习笔记——SQL SERVER的递归
- Coursera Algorithms week3 归并排序 练习测验: Counting inversions
- Django day08 多表操作 (二) 添加表记录
- 二进制部署Kubernetes-v1.14.1集群
- Win7的虚拟Wi-Fi
- 2015 多校赛 第四场 1010 (hdu 5336)
- invoke与call
- Spring Boot (1) 构建第一个Spring Boot工程
- struts2标签(五)
- HTML+CSS(10)