剑指offer中位运算技巧
来源:互联网 发布:淘宝品控违规描述不符 编辑:程序博客网 时间:2024/05/20 22:30
public class first { public static void main(String args[]){//A是第一列,B是第二列,z是第26列,AB是第27列,输入一串字符串,求是第几列 Scanner cin=new Scanner(System.in); String s=cin.next(); int sum=0; for (int i=0;i<s.length();i++){ sum=sum*26+s.charAt(i)-'A'+1; } cin.close(); System.out.println(sum); }}
public class Second {public static void main(String args[]){//统计一个整数表示的二进制中最多有多少个1Scanner cin=new Scanner(System.in);int n=cin.nextInt();cin.close();int num=0;while(n!=0){n=(n-1)&n;//相当于将整数二进制最右边一个1变成0num++;}System.out.println(num);}}
public class third {//判断一个整数是否为2的整数次方public static void main(String args[]){Scanner cin=new Scanner(System.in);int n=cin.nextInt(); cin.close(); n=(n-1)&n;//去掉唯一一个1 if (n==0) System.out.println("是2的整数次方"); else System.out.println("不是2的整数次方"); }}
public class fourth { public static void main(String args[]){//输入m和n.计算改变m的二进制的几位才能得到m的二进制,比如10的二进制是1010,13的二进制是1101需要改变3位才能得到1101 Scanner cin=new Scanner(System.in); int n=cin.nextInt(); int m=cin.nextInt(); cin.close(); int c=n^m;//先求异或 int num=0; while(c!=0){ c=(c-1)&c; num++; } System.out.println(num); }}
0 0
- 剑指offer中位运算技巧
- 【剑指Offer】位运算
- 剑指offer-位运算
- 剑指offer,位运算相关
- 剑指offer: 二进制中1的个数(位运算)
- 【剑指Offer】二进制中1的个数(位运算)
- 剑指Offer之面试位运算总结
- 剑指offer 算法 (位运算)
- 剑指offer面试题10 二进制中1的个数(位运算专题)
- 【剑指offer】位运算相关-二进制中1的个数10
- 剑指offer 2.4 位运算,求二进制中1的个数
- 【剑指offer】2.4.3位运算——面试题10:二进制中1的个数
- 《剑指offer》:[14]位运算以及求二进制中1的个数
- 剑指offer-面试10:二进制中1的个数(位运算)
- 剑指offer 10题 【位运算】二进制中1的个数
- 剑指offer——面试题10:位运算之二进制中1的个数
- 《剑指Offer》位运算——求二进制数中1的个数
- 剑指offer:(10)位运算,计算二进制中1的个数
- 算法——递推算法
- fiddler抓包工具【一】
- 根据时间段去做查询条件
- Objective-C库文件使用小记
- 用SpannableString打造绚丽多彩的文本显示效果
- 剑指offer中位运算技巧
- 字符串的替换和拆分
- 怎么给MindManager数据库导入数据连接
- Revit API 开发 (3): 一个使用过滤器(filter)的例子
- 扎克伯格的26张PPT帮助你提高工作效率
- 笔记:c++的const类成员函数(1)
- RabbitMQ消息队列(一): Detailed Introduction 详细介绍
- 比较Java不同压缩算法的性能
- css3常用属性animation-play-state的使用技巧