posts - 99,  comments - 8,  trackbacks - 0

用hash 怎么做呢?

#include <iostream>
#include 
<string>
using namespace std;

int main ()
{
    
int t;
    
int n;
    
while ( scanf ("%d"&t) != EOF )
    
{
          
for ( int i = 0; i < t; i ++ )
          
{
              scanf ( 
"%d"&n );
              
bool flag = 0;
              
int count = 0;
              
while ( n != 1 )
              
{                    
                    
if ( n % 2 == 0 )
                    
{
                         n = n / 2;
                       
                    }
                    else 
if ( n % 2 != 0 )
                    
{
                         count ++;
                         flag = 1;
                         count == 1 ? printf ("%d", n) : printf (" %d", n);
                         n = n * 3 + 1;
                        
                    }
              }

              
if ( !flag )
              printf (
"No number can be output !\n");
              
else
              printf (
"\n");
          }

    }


    
// system ("pause");
     return 0;
}

posted on 2010-08-28 11:27 雪黛依梦 阅读(222) 评论(0)  编辑 收藏 引用 所属分类: 简单题哈希法

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜