alexander_vc的专栏

让我们为了共同的梦想走到一起来..

用户操作
[即时聊天] [发私信] [加为好友]
张建辉ID:alexander_vc
6624次访问,排名15459(1),好友17人,关注者36人。
2006~2007 广东易天科技有限公司实习
2005~2006 学校研发室做软件开发实习
alexander_vc的文章
原创 10 篇
翻译 0 篇
转载 17 篇
评论 7 篇
张建辉的公告
希望能够和更多的IT人成为最好的朋友...
最近评论
nerv3x3:好!!!一举解决我的疑惑,刚刚还找了半天不知道怎么添加事件处理程序...
czdvcc:wow power leveling
fang235one_:太多了,不知道怎么选
thecorr:呵呵~ 兄弟 俺倒是真想和你大做一场。
可惜前阵忙着找工作,未能如愿,真是抱歉~!~~
alexander_vc:希望大家都去加入哦
文章分类
收藏
    相册
    风采依旧
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 黑洞6714收藏

    新一篇: 觅寻知音誓言书 | 旧一篇: 如何在VS2005中自动添加事件处理函数?

    #file:hole.h

    class hole
    {
    public:
     void convert(int &org);
     void compare(int &org,int n=4);
     void sub(int &max,int &min);
     void show();
    private:
     int origin;
        static int step;
     int max,min;
    };

    #file:hole.cpp

    #include "hole.h"
    #include <iostream.h>
    int hole::step=0;
    void hole::convert(int &org)
    {
     origin=org;
     if(org!=6174)
     {
     // step++;
      compare(org);
      
     }
    }

    void hole::sub(int &max,int &min)
    {
     step++; 
        origin=max-min;
     convert(origin);
       
    }

    void hole::compare(int &org,int n)
    {
     int temp;//,k;
     static int a[4]={0};
      //  int a[4]={0};
     if(0==n)  //这里采用了数据结构中的冒泡排序算法
     {
        for(int i=1;i<=3;i++)
        {
        // k=i;
         for(int j=0;j<4-i;j++)
         if(a[j]>a[j+1])
          {
            temp=a[j];
           a[j]=a[j+1];
           a[j+1]=temp;
          }
        
        
        }
        min = a[0]*1000+a[1]*100+a[2]*10+a[3];
        max=a[3]*1000+a[2]*100+a[1]*10+a[0];
           if(max==min || max==0 || min==0)
        {
         cout<<"此数据无法从黑洞中逃脱,步数无限...."<<endl;
         return;
        }
           //Test
        //cout<<"max="<<max<<endl;
        //cout<<"min="<<min<<endl;
        sub(max,min);
     }
     else  //这里采用了递归调用的算法
     {
      a[n-1]=org%10;
      org=org/10;
      hole::compare(org,n-1);
     }

    }
    void hole::show()
    {
      if(max==min || max==0 || min==0)
      {
       return ;
      }
      else
      {
        cout<<"Total step is :"<<step<<endl;
      }
    }

    #file:hole_main.cpp

    #include <iostream>
    using namespace std;
    #include "Hole.h"

    int main()
    {
     int x;
     cout<<"please input data (四位整数) :"<<endl;
     cin>>x;
     hole hl;
     hl.convert(x);
     hl.show();
     return 0;
    }

    /////这是我的测试数据..........

    黑洞6174问题:
    为什么对所有数据的组合进行的测试,只有少数的几组数据得到的结果需要7步,而其同一组数据的其他组合
    却得不到7?
    1235
    7
    5321
    7
    2135
    7
    1325
    7
    2315
    7
    2513
    7

    2531
    7
    1523
    7
    1532
    7
    //////////////////////////////////////////
    3125
    7
    3215
    7
    3251
    7

    3521
    7

    3512
    7

    /////////////////////////////////////////////
    5123
    7
    5132
    7

    5231
    7
    5213
    7
    5312
    7

    5321
    7

    ////////////////////////////////////////
    8888 此数据无法从黑洞中逃脱,步数无限...."<<
    5555 此数据无法从黑洞中逃脱,步数无限...."<<

    经过测试所有的四位数字只要不相等就就可以得到需要7步才可以退出程序.....

    就需要经过7步才可以保证相减的差等于6714.............

    发表于 @ 2007年11月04日 13:02:00|评论(loading...)|编辑

    新一篇: 觅寻知音誓言书 | 旧一篇: 如何在VS2005中自动添加事件处理函数?

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 张建辉