将n的k位清0】的更多相关文章

实例三:将n的k位清0 方法: result= n &~(1<<k) 使第k为变成0,再与运算,0和任何数进行与运算都是0. 解释:  0000 0001 ---- 1 左移k位  0000 1000 取反操作  1111 0111 原数 1111 1111 取反后与原数进行与操作 结果 1111 0111 ---- k清零 int _tmain(int argc, _TCHAR* argv[]){ int n,k,nResult=0; cout << "请输入原…
下面是使用a数组本身完成: package 数组元素k位右移; /** * 数组向又移动k位. 0<k<n * * @author SeeClanUkyo 将一组数组向右移动k位,末尾的要转置移动到数组开始,其中n为数组大小,0<k<n */ public class ArrayMoveK { public static void main(String[] args) { int k = 3; int[] a = { 1, 2, 3, 4, 5 }; arrayMoveK(a,…
function digit(num,k){         var knum = 0;         for(var i=1; i<=k; i++){                 knum = num%10;                 num = parseInt(num/10);         }         return knum; }…
Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of num is less than 10002 and will be ≥ k. The given num does not contain any leading zero. Ex…
#include<stdio.h> #include<math.h> int main() { int A,k,B,sum,c,d; while(scanf("%d%d%d",&A,&B,&k)&&(A||B)) { if(A%(c=pow(10.0,k))==B%(d=pow(10.0,k))) { sum=-; } else { sum=A+B; } printf("%d\n",sum); } }…
今晚做了下某公司的网络笔试题,好久没刷题了,现在渣得要死,里面有道程序设计题是 把一个数组向右循环移动k位要求时间复杂度为O(n) 给的方法定义为 public void solution(int a[],int length,int k) 我当时觉得挺容易的,结果一写出来发现只能移一位... public void solution(int []a,int length,int k){ int temp=a[length-1]; for(int j=length-1;j>0;j--){ a[j…
Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of num is less than 10002 and will be ≥ k. The given num does not contain any leading zero. Ex…
题目描述 读入两个小于10000的正整数A和B,计算A+B.需要注意的是:如果A和B的末尾K(不超过8)位数字相同,请直接输出-1. 输入描述: 测试输入包含若干测试用例,每个测试用例占一行,格式为"A B K",相邻两数字有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 输出描述: 对每个测试用例输出1行,即A+B的值或者是-1. 分析 关键在于获得整数的末k位,个位 = a%10, 十位个位 = a%100依次类推 if(a % ((int)pow(10, k))…
实例四:将n的k位s置1 方法:result =n|(1<<k) 只使k位变为1,其他位为0,再进行或操作,1与任何数的或操作都是1. 解释: 原数 0000 1011 ---11 数值1   0000 0001 ---11左移    0000 0100 ---4和原数或操作 0000 1111 //与原数比0变为1 值为15 int _tmain(int argc, _TCHAR* argv[]){ int n,k,nResult = 0; cout << "请输入原始…
实例二:取n的第k位 方法:a>> k & 1 某值a右移K位后与整数“1”进行与运算.即把需要第几位就右移几位. 例子: 0000 1000 ------8右移3位 0000 0001 ------1与1进行与操作 0000 0001 ------1 结果:   0000 0001 ------1 代码:int _tmain(int argc, _TCHAR* argv[]){ int nValue,k,nResult=0; cout << "请输入要进行处理的…