极速多用户网页音乐播放器(框架固定形式/底部音乐播放器)
<div><p>此网页使用了框架,但您的浏览器不支持框架。</p></div>

不用+和-实现变量加1的代码

看到一个面试题,要求不用+和-实现变量加1操作。就写了下,不知道有没有更简单的。

代码如下:

 1 #include<iostream>
 2 
 3 using std::cout;
 4 using std::cin;
 5 using std::endl;
 6 
 7 int main()
 8 {
 9     while(1)
10     {
11         int result = 0;
12         cout << "input data:";
13         cin >> result;
14 
15         if (result % 2)
16         {
17             int tmp = 1;
18             while(result == (result | tmp))
19             {
20                 result = result & (~tmp);
21                 tmp = tmp << 1;
22             }
23             result = result | tmp;
24         }
25         else
26         {
27             result = result | 1;
28         }
29         cout << "result is:" << result << endl;
30     }
31     return 0;
32 }
View Code

 

posted @ 2013-05-16 18:17  飞鼠溪  阅读(197)  评论(0编辑  收藏  举报