摘要: 来自剑指offer #includeusing namespace std;double power(int b, int e){ if (e >1); res *= res; if (e & 0x1) { res = res*b; } return re... 阅读全文
posted @ 2017-03-07 23:33 乐天的java 阅读(69) 评论(0) 推荐(0)
摘要: 位运算实现加法,模拟十进制加法,首先位数相加, 如19 + 12 = 21 再加上进位 9+2进一位 21 + 10 = 31 #includeusing namespace std;int add(int a, int b){ if (b == 0) { ... 阅读全文
posted @ 2017-03-07 23:31 乐天的java 阅读(68) 评论(0) 推荐(0)
摘要: 将一串数字逆转 输入123456 输出654321 循环解法 #includeusing namespace std;int reverse(int a){ int temp = 0; int i; while (a) { i = a % 10; temp... 阅读全文
posted @ 2017-03-07 23:29 乐天的java 阅读(82) 评论(0) 推荐(0)
摘要: 有n个台阶,一次走一步或者两步或者n步,有多少种可能 ? 同台阶问题 f(n)=f(n-1)+f(n-2)+...f(1) f(n-1)=f(n-2)+f(n-3)+....f(1) 所以f(n)=f(n-1)+f(n-1)=2*f(n-1) #incl... 阅读全文
posted @ 2017-03-07 23:25 乐天的java 阅读(75) 评论(0) 推荐(0)
摘要: 腾讯面试题,有50个台阶,一次走一步或者两步,有多少种可能 ? 假设n台阶有f(n)中可能的走法,则n-1台阶有f(n-1)中走法,n-2台阶有f(n-2)走法,第n节台阶,有两种走法可能是一步跨上,也可能是2步跨上,所以f(n)=f(n-1)+f... 阅读全文
posted @ 2017-03-07 23:22 乐天的java 阅读(90) 评论(0) 推荐(0)
摘要: //利用循环的解法,效率高#includeusing namespace std;int facii(int n){ if (n > n; y = facii(n); cout using namespace std;int f(int n){ if (n >... 阅读全文
posted @ 2017-03-07 23:20 乐天的java 阅读(48) 评论(0) 推荐(0)
摘要: #includeusing namespace std;bool judge(int arr[],int i){ if (i <= 1) { return true; } if (arr[i] < arr[i - 1]) { return false; }... 阅读全文
posted @ 2017-03-07 23:18 乐天的java 阅读(219) 评论(0) 推荐(0)
摘要: #includeusing namespace std;void convert(int n){ if (n == 0) { return; } convert(n/2); cout > n; convert(n); system("pause");} ... 阅读全文
posted @ 2017-03-07 23:16 乐天的java 阅读(76) 评论(0) 推荐(0)