女朋友为了考驾照去找临时工作了,一天一百,过年不能回家了,心痛中。。。我一定要面试成功,为了我们未来的家。
这年代女孩都为了自己奋斗了,男生呢?男生呢?每个大学还有多少男生在玩?在荒废?那世界上呢,唉。。。
思路一
早时候我们做乘法思路如下
x=13,y=11,x*y=? x,y 表示成二进制如下
思路二
一直做直到 x == 1
排除x为偶数的,剩下的y加起来就是结果
test.cpp#include <iostream> using namespace std; // multi number int multi(int a,int b); int main() { int a,b,i = 0; while(i<100) { a = rand()%100,b = rand()%100; cout<<"a="<<a<<" ,b="<<b<<" ,a*b="<<multi(a,b)<<endl; i++; } system("pause"); return 0; } // multi number int multi(int a,int b) { bool fushu = false; if(a <= 0) { if( a==0 ) return 0; a = -a; fushu = !fushu ; } else if(b <= 0) { if( b==0 ) return 0; b = - b; fushu = !fushu ; } int result = 0 ; while( a >= 1 ) { if( a%2 != 0 ) result = result + b ; a = a/2; b = b*2; } if(fushu) result = - result; return result; }
原文:http://blog.csdn.net/cqs_experiment/article/details/18375027