1.A+B问题 给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符 思路:作异或得到未进位和,作与并向左移1位得到进位,随后再重复操作俩结果,直到进位为0,适合用递归 public int aplusb(int a, int b) { int sum = a ^ b; int ca = (a & b) << 1; if (ca == 0) { return sum; } return aplusb(sum, ca); } 2016-12-07 2.尾部的零 设计一个算法,
A. 门牌制作 答案 624 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int cnt = 0; for (int i = 1; i <= 2020; i++) { int x = i; while (x) { if (x % 10 == 2) ++cnt; x /= 10; } } cout << cnt <
Thinking in Java 4th 中.英文两版pdf文档,书中源码及课后习题答案.链接:https://pan.baidu.com/s/1BKJdtgJ3s-_rN1OB4rpLTQ 密码:2zc4 http://greggordon.org/java/tij4/solutions.htm 亦为Thinking in Java 4th英文版的课后习题答案. 使用Eclipse运行Thinking in Java 4rd例子源码:https://blog.csdn.net/u0135737
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, find the sequence of gray code. A gray code sequence must begin with 0 and
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow: F(k