首页 > 编程语言 > 详细

1数组和字符串题解

时间:2019-09-11 16:46:26      阅读:88      评论:0      收藏:0      [点我收藏+]

---恢复内容开始---

//第一题:给定16位整数被的输入字符串,以16进制输出,偏移数,字符的16进制转换数(8位),(8位), 字符,中间间隔2空格
mport java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); String str = in.next().trim(); int len = str.length(); for (int i = 0; i < len; i += 16) { System.out.printf("%08x ",i); for (int j = 0; j < 8; j++){ System.out.printf("%02x ",(int)str.charAt(i+j));//运行出错,原因,char 不能直接转为进制数,一定要先(int).%x表示16进制数,2表示输出2位,0表示,不够2位的用0占位,左对齐。-02,表,左对齐 } System.out.printf(" "); for (int j = 9; j < 16; j++){ System.out.printf("%02x ",(int)str.charAt(i+j)); } System.out.printf(" "); for (int j = 0; j < 16;j++) { System.out.printf("%c",(int)str.charAt(i+j)); } System.out.printf("\n"); } } // public static int find(int k, int a, int b) {//第二题,二叉树查找 // k = (int)Math.pow(2, k-2); // int root = (int)Math.pow(2, k-1); // for(; k>0; k/=2){ // if((a-root)*(b-root) <= 0) { // break; // } else { // if ((a-root) < 0){ // root = root - k; // } else { // root = root + k; // } // } // } // return root; // } }

 

技术分享图片

1.技术分享图片

2.

菜鸟★桥:
先利用hash表将输入的字符串s中ABCD的个数记录在数组N中。然后for(int i =0;i<len;i++)循环里把数组N减去当前s[i]字符的个数,然后对于当前的s[i]把数组N中所有小于s[i]的字母对应发的数字相加即可。这个循环做完就得到逆序数。
编程

归并排序: 我们可以总结出统计逆序对的过程:先把数组分隔成子数组, 先统计出子数组内部的逆序对的数目,然后再统计出两个相邻子数组之间的逆序对的数目。在统计逆序对的过程中,还需要对数组进行排序。如果对排序贺,法很熟悉,我们不难发现这个排序的过程实际上就是归并排序。

http://wiki.jikexueyuan.com/project/for-offer/question-thirty-six.html

技术分享图片

---恢复内容结束---

1、确定字符串的所有字符是否全不同

  1)

1数组和字符串题解

原文:https://www.cnblogs.com/lingli-meng/p/6671937.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!