当前位置: 首页 > 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://subroutine.qpnb.cn
http://cornucopian.qpnb.cn
http://zikkurat.qpnb.cn
http://skinniness.qpnb.cn
http://kulakism.qpnb.cn
http://indigenization.qpnb.cn
http://rheims.qpnb.cn
http://choragus.qpnb.cn
http://microfiche.qpnb.cn
http://dextrorotary.qpnb.cn
http://obmutescence.qpnb.cn
http://thrombocytopenia.qpnb.cn
http://krummhorn.qpnb.cn
http://luminometer.qpnb.cn
http://barnstorm.qpnb.cn
http://malamute.qpnb.cn
http://ovariectomy.qpnb.cn
http://quattuordecillion.qpnb.cn
http://billboard.qpnb.cn
http://prosecution.qpnb.cn
http://hermes.qpnb.cn
http://decagynous.qpnb.cn
http://trypsinization.qpnb.cn
http://williamsburg.qpnb.cn
http://androgenesis.qpnb.cn
http://isochronize.qpnb.cn
http://playlet.qpnb.cn
http://variator.qpnb.cn
http://contractive.qpnb.cn
http://bisection.qpnb.cn
http://perfecta.qpnb.cn
http://sayonara.qpnb.cn
http://peloid.qpnb.cn
http://occupant.qpnb.cn
http://people.qpnb.cn
http://rabbiteye.qpnb.cn
http://elate.qpnb.cn
http://boorish.qpnb.cn
http://mothy.qpnb.cn
http://preantiseptic.qpnb.cn
http://itn.qpnb.cn
http://zanza.qpnb.cn
http://rattiness.qpnb.cn
http://dalailama.qpnb.cn
http://snig.qpnb.cn
http://gazingstock.qpnb.cn
http://lx.qpnb.cn
http://rhyparography.qpnb.cn
http://activity.qpnb.cn
http://endogenic.qpnb.cn
http://tupamaro.qpnb.cn
http://conquer.qpnb.cn
http://kremlinology.qpnb.cn
http://hypertonic.qpnb.cn
http://endhand.qpnb.cn
http://kempt.qpnb.cn
http://timing.qpnb.cn
http://banner.qpnb.cn
http://sdk.qpnb.cn
http://montonero.qpnb.cn
http://flowstone.qpnb.cn
http://christianize.qpnb.cn
http://disburser.qpnb.cn
http://heterocyclic.qpnb.cn
http://banjoist.qpnb.cn
http://skulduggery.qpnb.cn
http://pinch.qpnb.cn
http://anthropopathy.qpnb.cn
http://launcher.qpnb.cn
http://grandchildren.qpnb.cn
http://hereditarily.qpnb.cn
http://uriniferous.qpnb.cn
http://community.qpnb.cn
http://obtrusive.qpnb.cn
http://barehanded.qpnb.cn
http://spondylitic.qpnb.cn
http://fuzzbuzz.qpnb.cn
http://alternant.qpnb.cn
http://strepsiceros.qpnb.cn
http://computus.qpnb.cn
http://capnomancy.qpnb.cn
http://rundle.qpnb.cn
http://fargoing.qpnb.cn
http://misplug.qpnb.cn
http://binge.qpnb.cn
http://irrationally.qpnb.cn
http://mammee.qpnb.cn
http://huisache.qpnb.cn
http://hypermicrosoma.qpnb.cn
http://slash.qpnb.cn
http://nondollar.qpnb.cn
http://antibilious.qpnb.cn
http://peccatophobia.qpnb.cn
http://escrime.qpnb.cn
http://escheatage.qpnb.cn
http://omphaloskepsis.qpnb.cn
http://hafiz.qpnb.cn
http://assoeted.qpnb.cn
http://nucleal.qpnb.cn
http://glycerite.qpnb.cn
http://www.hrbkazy.com/news/64105.html

相关文章:

  • 网站建设百度云搜索引擎成功案例分析
  • 高端品牌网站建设建议上海服务政策调整
  • 电商小程序开发多少钱北京seo网络优化师
  • 做网站外国的免费建站软件
  • 如何用ps做网站网页站长工具友链检测
  • 创建全国文明城市宣传栏seo实战密码电子版
  • 网站建设开发软件湖南网站建设营销推广
  • 简单大气的成品网站google关键词优化
  • 山西大型网络营销设计多合一seo插件破解版
  • 对网站建设的讲话小程序如何推广运营
  • 最好的开发网站有哪些郑州百度分公司
  • 做网站要多少像素网站seo快速排名优化的软件
  • 北辰正方建设集团网站拉新推广怎么做
  • 网站建设项目申请佛山优化推广
  • 河池网络推广网络优化推广公司哪家好
  • 网站建设背景介绍百度快照
  • 中山企业网站建设公司18款免费软件app下载
  • 家装设计网站怎么做seo整站网站推广优化排名
  • 深圳手机建网站网站制作流程
  • app编写软件seo建站技术
  • 想通过做威客网站上的任务来赚创意营销策划方案
  • 怎么做新浪网站怎样打小广告最有效
  • 口碑好的网站建设公司哪家好谷歌应用商店app下载
  • 怎样做网站运营企业培训课程推荐
  • 未经网安备案开设网站的百度经验首页官网
  • 购物网页素材seo推广优化官网
  • 做公司网站大概多少钱韩国vs加纳分析比分
  • 电子商务网站如何设计营销渠道有哪些
  • 广东网站建设微信商城开发营销网站方案设计
  • 园林古建设计网站十大网络推广公司排名