当前位置: 首页 > news >正文

如何查看网站空间大小wordpress怎么翻页

如何查看网站空间大小,wordpress怎么翻页,网站建设公司口碑排名,优化王题目: 哈夫曼编码大全 描述: 关于哈夫曼树的建立,编码,解码。 输入 第一行输入数字N,代表总共有多少个字符以及权值 第二第三行分别是一行字符串,以及每个字符对应的权值 接下来输入一个数M,表…

题目: 哈夫曼编码大全
描述:
关于哈夫曼树的建立,编码,解码。

输入
第一行输入数字N,代表总共有多少个字符以及权值
第二第三行分别是一行字符串,以及每个字符对应的权值
接下来输入一个数M,表示接下来有M行字符串,要求你对每个字符串进行编码
再输入一个数X,表示接下来有X行编码,要求你对每行编码进行解码

输出
第一行输出所有节点的权重
接下来输出N行,每行以 “a:001”的格式输出每个字符对应的编码
接着输出M行,对输入的字符串的编码结果
最后,输出X行的解码结果
输入样例

6
abcdef
50 10 5 5 20 10
2
abcdef
defabaabbc
2
011001100100110110101101100
1100011000110101100101100

输出样例

50 10 5 5 20 10 10 20 30 50 100
a:0
b:100
c:1100
d:1101
e:111
f:101
010011001101111101
11011111010100001001001100
accbdfadb
cacadacfb

参考:
本题代码请删除所有中文(包括注释),否则编译错误,无法通过

import java.util.*;public class Main {private static class Node{int value, lchild, rchild, parent;}public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();String str = sc.next();Node[] hfm = new Node[2 * n - 1];for (int i = 0; i < n; i++) {hfm[i] = new Node();hfm[i].value = sc.nextInt();}for (int i = 0; i < n - 1; i++) {// l1 记录最小叶节点下标,l2 记录次小叶节点下标int l1 = -1, l2 = -1;for (int j = 0; j < n + i; j++) {if (hfm[j].parent == 0 && (l1 == -1 || hfm[j].value < hfm[l1].value)) {l2 = l1;l1 = j;} else if (hfm[j].parent == 0 && (l2 == -1 || hfm[j].value < hfm[l2].value)) {l2 = j;}}hfm[n + i] = new Node();hfm[n + i].value = hfm[l1].value + hfm[l2].value;hfm[n + i].lchild = l1;hfm[n + i].rchild = l2;hfm[l1].parent = hfm[l2].parent = n + i;}// 输出所有节点权重for (int i = 0; i < 2 * n - 1; i++) {System.out.print(hfm[i].value + " ");}System.out.println();// 对每个字符编码String[] code = new String[n];for (int i = 0; i < n; i++) {StringBuilder sb = new StringBuilder();int child = i, parent = hfm[i].parent;while (parent != 0) {if (hfm[parent].lchild == child) {sb.append('0');} else {sb.append('1');}child = parent;parent = hfm[parent].parent;}code[i] = String.valueOf(sb.reverse());}// 输出字符的编码for (int i = 0; i < n; i++) {System.out.println(str.charAt(i) + ":" + code[i]);}// 对字符串编码int m = sc.nextInt();for (int i = 0; i < m; i++) {String s = sc.next();for (int j = 0; j < s.length(); j++) {int id = str.indexOf(s.charAt(j));System.out.print(code[id]);}System.out.println();}// 对字符串解码int x = sc.nextInt();for (int i = 0; i < x; i++) {String s = sc.next();int now = 0;while (now < s.length()) {for (int j = 0; j < n; j++) {int idx = s.indexOf(code[j], now);if (idx == now) {now += code[j].length();System.out.print(str.charAt(j));break;}}}System.out.println();}}
}
http://www.yayakq.cn/news/205182/

相关文章:

  • 旅游网站的设计方案怎么做如何建立自己的公司
  • 怎么样做网站推广北京市住房和城乡建设局官网
  • 小区百货店网怎么做网站oa系统有哪些功能
  • 安卓开发软件有哪些宁波seo怎么推广
  • 宠物之家网站开发wordpress安装主题报错
  • 写建设网站的具体步骤高端网站建设注意
  • 漂流瓶做任务网站百度seo快速排名优化
  • 郑州网站建设创业广州站到广州南站地铁要多久
  • 网站建设服务费税率多少寿光网站建设价格
  • 网站建设登录界面代码首页关键词优化价格
  • 有关网站开发的外文文献网站建设相关语言
  • 网站后台编辑框不显示微信小程序开发怎么做
  • 宁波模板做网站购物网站功能报价
  • 南京网站建设学习扁平化网站导航ui模板
  • 网站视图错位网站被跳转公告怎么写
  • 技术支持 东莞网站建设机械加工百度推广运营专员
  • 网站建设福州公司wordpress打开提速
  • 视频教做家常菜的网站手机兼职有哪些
  • 扶余市建设局网站wordpress主题中英文
  • 帝国做的网站打开速度拓普网站建设
  • 涟水网站建设宁晋县建设局网站
  • 厦门哪里有教网站建设WordPress关键词过滤
  • 南浔哪有做网站的金科做的网站
  • 东莞网站建设及外包室内装饰网站模板
  • 设计感网站襄阳营销型网站
  • 河南网站建设华企祥云不用花生壳做网站服务器
  • 朔州路桥建设有限责任公司网站设计师学校有哪些
  • 昆明网站建设系统浏览器禁止网站怎么做
  • 包装设计的网站网站常用字体
  • 网络游戏开发培训上海网站关键词优化