650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/7F/DF/wKiom1cwQm6hRaQ2AAKd4HogHfc459.jpg "style=" float: none; "title=" QQ picture 20160507133124.jpg "alt=" Wkiom1cwqm6hraq2aakd4hoghfc459.jpg "/>
Class solution {public: int fibonacci (int n) {int i=2; int prev=0,cur=1; if (n==0) return 0; if (n==1) return 1; while (i++<=n) { int tmp=cur; cur=cur+prev; prev=tmp; } return cur; }};
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7F/DC/wKioL1cwQ03h6KxvAAO9FAwQAF0448.jpg "style=" Float:none, "title=" QQ picture 20160507133128.jpg "alt=" wkiol1cwq03h6kxvaao9fawqaf0448.jpg "/>
Class solution1 {public: int numberof1 (int n) { int i=0; int tag=1; int count=0; while (i++ <32) { if ((n& (tag))!=0) count++; tag=tag<<1; } return count; }};//Optimal Solution Class soluTion {public: int numberof1 (int n) { int i=0; while (n ) { n= (n-1) &n; i++; } return i; }};
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/7F/DF/wKiom1cwQnOgUj87AAKoaKxZrbM902.jpg "style=" float: none; "title=" QQ picture 20160507133136.jpg "alt=" Wkiom1cwqnoguj87aakoakxzrbm902.jpg "/>
Class Solution {Public:double Power (double base, int exponent) {if (exponent==0) return 1; if (exponent<0&&base!=0) return 1/base*power (base,exponent+1); Return Base*power (base,exponent-1); }};
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/7F/DC/wKioL1cwQ1GgGnjmAAK5bqBsklQ112.jpg "style=" float: none; "title=" QQ picture 20160507133140.jpg "alt=" Wkiol1cwq1gggnjmaak5bqbsklq112.jpg "/>
int Numadd (char* num, int bit) {int i = Bit,needcarry=1;char carry = 1;while (i >0) {num[i-1]+=carry; Num[i] = ' 0 '; if (num [I-1] <= ' 9 ') {Needcarry = 0;break;} -----I.} if (Needcarry = = 1) {num[0] = ' 1 '; Num[bit + 1] = ' 0 ';} return Needcarry;} void Print1ton (int n) {if (n <= 0) Return;char num[max_size] = {0};int i = 0;while (1) {if (num[i]< ' 0 ') num[i] = ' 0 '; if (++num[i]> ' 9 ') {if (Numadd (num, i) = = 1) ++i;} if (i = = N) break;cout << num << ';//_sleep (100);} cout << Endl;}
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/7F/DC/wKioL1cwQ1bgi6hYAAMdhCblyWU547.jpg "style=" float: none; "title=" QQ picture 20160507133148.jpg "alt=" Wkiol1cwq1bgi6hyaamdhcblywu547.jpg "/>
C + +; some questions per week (2)