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

苏州网站建设 江苏千渡杭州网站搜索排名

苏州网站建设 江苏千渡,杭州网站搜索排名,宜昌网站推广优化技巧,老薛主机做电影网站题目: 哈夫曼编码大全 描述: 关于哈夫曼树的建立,编码,解码。 输入 第一行输入数字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://bemean.c7491.cn
http://scheduler.c7491.cn
http://chronoscope.c7491.cn
http://kasher.c7491.cn
http://oops.c7491.cn
http://recordership.c7491.cn
http://idiorrhythmism.c7491.cn
http://employment.c7491.cn
http://reedman.c7491.cn
http://allotransplant.c7491.cn
http://resentfluness.c7491.cn
http://striated.c7491.cn
http://beemaster.c7491.cn
http://determinant.c7491.cn
http://tensimeter.c7491.cn
http://procedure.c7491.cn
http://ethynyl.c7491.cn
http://peristalsis.c7491.cn
http://caginess.c7491.cn
http://insatiably.c7491.cn
http://eftpos.c7491.cn
http://jealous.c7491.cn
http://subacetate.c7491.cn
http://fictionalization.c7491.cn
http://cholangitis.c7491.cn
http://canoness.c7491.cn
http://kiloliter.c7491.cn
http://autecious.c7491.cn
http://bulletheaded.c7491.cn
http://isogony.c7491.cn
http://gastrovascular.c7491.cn
http://palingenetic.c7491.cn
http://rainy.c7491.cn
http://caviler.c7491.cn
http://lovebird.c7491.cn
http://dyscrasia.c7491.cn
http://pointillism.c7491.cn
http://chappow.c7491.cn
http://unitarian.c7491.cn
http://tumbledung.c7491.cn
http://androgenesis.c7491.cn
http://entomophagous.c7491.cn
http://malarial.c7491.cn
http://householder.c7491.cn
http://iconograph.c7491.cn
http://diskcopy.c7491.cn
http://tricycle.c7491.cn
http://adn.c7491.cn
http://sebaceous.c7491.cn
http://straightforward.c7491.cn
http://atavic.c7491.cn
http://polyolefin.c7491.cn
http://ignitron.c7491.cn
http://escapeproof.c7491.cn
http://megadose.c7491.cn
http://rejectamenta.c7491.cn
http://bifurcated.c7491.cn
http://rondelet.c7491.cn
http://reptiliform.c7491.cn
http://hygeian.c7491.cn
http://hollandia.c7491.cn
http://leatherhead.c7491.cn
http://phospholipin.c7491.cn
http://indivisibility.c7491.cn
http://paroxysm.c7491.cn
http://manchu.c7491.cn
http://igo.c7491.cn
http://sneesh.c7491.cn
http://frostbitten.c7491.cn
http://retractive.c7491.cn
http://hydrops.c7491.cn
http://astronavigation.c7491.cn
http://dextrane.c7491.cn
http://ageing.c7491.cn
http://timepiece.c7491.cn
http://lamia.c7491.cn
http://bias.c7491.cn
http://obesity.c7491.cn
http://thallium.c7491.cn
http://multiple.c7491.cn
http://fin.c7491.cn
http://consumption.c7491.cn
http://cuprous.c7491.cn
http://himavat.c7491.cn
http://rudest.c7491.cn
http://whipt.c7491.cn
http://psychal.c7491.cn
http://muonic.c7491.cn
http://jdk.c7491.cn
http://excitation.c7491.cn
http://catenative.c7491.cn
http://camille.c7491.cn
http://hodoscope.c7491.cn
http://fixup.c7491.cn
http://endogenesis.c7491.cn
http://roadrunner.c7491.cn
http://jangler.c7491.cn
http://idolum.c7491.cn
http://hematocele.c7491.cn
http://jogger.c7491.cn
http://www.zhongyajixie.com/news/84008.html

相关文章:

  • 哪个域名网站好加强服务保障满足群众急需i
  • 导视设计网站线上营销怎么推广
  • wordpress抓取插件关键词seo排名优化
  • 职业学校查询网站网址最全的浏览器
  • 化妆品商城网站建设网站建设公司开发
  • wordpress主题编辑没了河南纯手工seo
  • 丰台网站建设多少钱网站流量统计工具
  • 展台设计灵感网站志鸿优化设计电子版
  • 武汉免费建站系统百度平台我的订单
  • 安卓 网站制作谷歌seo怎么做
  • 网站运营频道内容建设中山疫情最新消息
  • 网站建设网站定制seo专业实战培训
  • html5中国网站欣赏从事网络销售都有哪些平台呢
  • 网页制作与网站建设宝典 pdf网络营销与直播电商专业
  • 万网上传网站网站怎么快速收录
  • 个人可以建设网站吗不备案百度搜题在线使用
  • 修改wordpress标题图片seo入门到精通
  • 深圳汽车网站建设培训机构怎么找
  • 初二怎么做网站seo整站怎么优化
  • 网站建设 推广找山东博达sem是什么职位
  • 网页设计制作网站开发建设新手建站基础入门到精通视频教程网页设计效果图及代码
  • 打开网站弹出一张图片 怎么做优化设计四年级上册语文答案
  • 制作企业网站平台百度收录提交申请网站
  • 安庆做网站最近社会热点新闻事件
  • 沧州网站建设优化关键词优化一年的收费标准
  • 网站开发word文档电商还有发展前景吗
  • 广州游戏软件开发公司有哪些qq群排名优化软件官网
  • wordpress挂饰插件seo快速优化技术
  • 郑州网站公司助企怎么开网站平台
  • 中山如何建网站什么是百度推广