lzmagic  
1/4桶水荡漾
日历
<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
统计
  • 随笔 - 7
  • 文章 - 0
  • 评论 - 0
  • 引用 - 0

导航

常用链接

留言簿

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
    Nice and Sunsan play the game of multiplication by ultiplying an integer p by one of the number2 2 to 9.Nic always starts with p = 1, does his multiplication.Then Susan multiplies the number, then Nic and so on. Before a game starts, they draw an integer 1<= n <= 4,294,967,295 and the winner is who first reaches p>=n.

Inuput: Each line of input contains one integer number n and ends while n = 0.
Output: For each line of input output one line either
            Nic wins.       
            or
            Susan wins.
            Assume that both of them play perfectly.
Sample Input:
162
17
34012226
0
Output for the Sample Input:
Nic wins.
Susan wins.
Nic wins.

 1/*Sulution: Nic(1st) wins over [1, 9], Susan(2nd) wins over [10, 18], Nic(1st) wins over [19, 162], Susan(2nd) wins over [163, 344], think a little and easy know why, then wo can get that 9 * 2 -> 18 * 9 -> 162 ->344……
 2*/

 3
 4#include<iostream>
 5
 6using namespace std;
 7
 8int main()
 9{
10    int n, a, b;
11    bool isFirWin;
12
13    cin >> n;
14    while(n != 0)
15    {
16        a = 1
17        b = 9;
18        isFirWin = true;
19
20        do
21        {
22            if(a <= n && n <= b) break;
23            else
24            {
25                a = b + 1;
26
27                if(isFirWin)
28                {
29                    b = b * 2;
30                    isFirWin = false;
31                }

32                else
33                {
34                    b = b * 9;
35                    isFirWin = true;
36                }

37            }

38        }
while(1);
39
40        if(isFirWin) 
41            cout << "Nic wins.\n";
42        else
43            cout << "Susan wins.\n";
44
45        cin >> n;
46    }

47    
48    return 0;
49}
posted on 2008-03-30 22:49 lzmagic 阅读(111) 评论(0)  编辑 收藏 引用 所属分类: practising

标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
相关链接:
网站导航:




 
Copyright © lzmagic Powered by: 博客园 模板提供:沪江博客