| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9370 人关注过本帖
标题:关于教室的人气及发展的讨论
只看楼主 加入收藏
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
以下是引用woodhead在2006-6-23 12:58:57的发言:
我想,先把这个做完吧,等过些天考试的完成了,ajax也有空了再做难的。
确实如此~!

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-06-23 20:41
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
昏,已经101贴了。大家谁有时间先一起开作吧。我先试着写点,基于我前面发的那个框架。

http://myajax95./
2006-06-24 12:55
baidu
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:3811
专家分:0
注 册:2005-11-4
收藏
得分:0 
俺估计此事就此不了了之了

偶放弃所有文章版权,偶在BCCN论坛任何贴子,可转贴,可散发,可抄袭,可复制,可被冒名顶替,可被任何人引用到任何文章中且不写出引文出处,偶分文不取。
2006-06-24 13:58
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

主要是考试,暑假绝对全力以赴


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-06-24 14:07
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
收藏
得分:0 
[CODE]
//====================== main.cpp =====================

#include <iostream>
#include <algorithm> //use for_each()
#include "tower.h"

using namespace std;

class X
{
public:
void operator()(int element) { cout<<element<<' '; }
};


void output(tower&, tower&, tower&);
void hnt(tower&, tower&, tower&, int);


int main()
{
int n;
while(cin>>n)
{
tower a('a',n), b('b'), c('c');

output(a, b, c);

hnt(a,b,c,n);
}

return 0;
}


void hnt(tower &source, tower &target, tower &tmp, int num)
{
static tower &p1 = source, &p2 = target, &p3 = tmp;

if(num == 1)
{
if(source.move_top_to(target) == false)
cout<<"arithmetic error"<<endl;
else
output(p1, p2, p3);
return;
}

hnt(source, tmp, target, num-1);

if(source.move_top_to(target) == false)
cout<<"arithmetic error"<<endl;
else
output(p1, p2, p3);

hnt(tmp, target, source, num-1);
}


void output(tower &t1, tower &t2, tower &t3)
{
X x;

cout<<t1.towerlabel()<<' ';
for_each(t1.begin(), t1.end(), x);
cout<<'\n';

cout<<t2.towerlabel()<<' ';
for_each(t2.begin(), t2.end(), x);
cout<<'\n';

cout<<t3.towerlabel()<<' ';
for_each(t3.begin(), t3.end(), x);
cout<<'\n';

cout<<"--------------------"<<endl;
}

//=================== tower.h ================
#ifndef TOWER_H
#define TOWER_H

#include <vector>


template class std::vector<int>;
class tower: public std::vector<int>
{
private:
const char label; //塔的标记,也许会有用

public:

tower(char ch, int m=0);
void set_plate(int); //初始化时用来设置tower中的盘子
char towerlabel() { return label; }
int top() { return this->back(); }
bool move_top_to(tower&); //从一个tower顶移动一个盘到另一个tower

};

#endif

/*可能用到的 vector<int> 的方法
iterator begin();
iterator end();
size_type size();
void clear();
void pop_back();
void push_back(int&);
*/

/===================== tower.cpp ====================
#include "tower.h"

tower::tower(char ch, int m):label(ch)
{
set_plate(m);
}

void tower::set_plate(int m)
{
clear();
for(int i=m; i>0; i--)
push_back(i);
}

bool tower::move_top_to(tower &target)
{
//移动之前检查是否违反规则
if(this == &target || this->empty())
return false;
if((!target.empty()) && (this->top() >= target.top()) )
return false;
//移动
target.push_back(this->top());
this->pop_back();
return true;
}
[/CODE]

不会界面,先编一个console程序,也许算不了什么,希望有所帮助。
给aogun看了个has a,这个改了改,改成is a了,
[QUOTE]
俺估计此事就此不了了之了650)this.style.width=650;" align="middle" border="0">
[/QUOTE]
谢谢鼓励

2006-06-24 15:25
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
收藏
得分:0 
改了一下,报错改成扔异常


[CODE]
//================== main.cpp ======================
#include <iostream>
#include <algorithm> //use for_each()
#include "tower.h"

using namespace std;
class ArithmeticException{};
class X
{
public:
void operator()(int element) { cout<<element<<' '; }
};


void output(tower&, tower&, tower&);
void hnt(tower&, tower&, tower&, int);


int main()
{
int n;
while(cin>>n)
{
tower a('a',n), b('b'), c('c');
output(a, b, c);

try {
hnt(a,b,c,n);
}
catch(ArithmeticException e)
{
cout<<"arithmetic failed";
break;
}
}

return 0;
}


void hnt(tower &source, tower &target, tower &tmp, int num) //递归算法
{
static tower &t1 = source, &t2 = target, &t3 = tmp;

if(num == 1)
{
if(source.move_top_to(target) == false)
throw ArithmeticException();
else
output(t1, t2, t3);
return;
}

hnt(source, tmp, target, num-1);

if(source.move_top_to(target) == false)
throw ArithmeticException();
else
output(t1, t2, t3);

hnt(tmp, target, source, num-1);
}


void output(tower &t1, tower &t2, tower &t3)
{
X x;

cout<<t1.towerlabel()<<' ';
for_each(t1.begin(), t1.end(), x);
cout<<'\n';

cout<<t2.towerlabel()<<' ';
for_each(t2.begin(), t2.end(), x);
cout<<'\n';

cout<<t3.towerlabel()<<' ';
for_each(t3.begin(), t3.end(), x);
cout<<'\n';

cout<<"--------------------"<<endl;
}[/CODE]

2006-06-24 15:50
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
我明天一早集成一下。

http://myajax95./
2006-06-24 16:09
wangxiang
Rank: 2
等 级:新手上路
威 望:5
帖 子:376
专家分:0
注 册:2006-3-28
收藏
得分:0 

支持参加所有人
不过,自己还有很多东西不会,估计只有看的份


2006-06-24 17:12
Satyr
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-7
收藏
得分:0 
关注.....

C++的博大精深让我叹服
2006-06-25 10:13
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

typedef vector<string> tower;
void towerChange(tower &t1,tower &t2,tower &t3,int count)
//t3是目的地,t1是初始地,t2是中途点,count表示移动的盘子数量
//将count个盘子从t1移动到t3
{
if(count!=0)
{
string temp=t1[t1.end()];
towerChange(tower &t1,tower &t3,tower &t2,int count-1);//将count-1个盘子从t1移动到t2
t1.pop_back();t2.push_back(temp);//将最下面的盘子移动t3;
dispaly();
towerChange(tower &t2,tower &t1,tower &t3,int count-1);//将count-1个盘子从t2移动到t3
}
else display();
}

void dispaly()
{
for(int i=0;i<count;i++)cout<<t1[i]<<" "<<t2[i]<<" "<<t3[i]<<endl;
}

只写了10分钟,估计错误还是有的,逻辑错误都有可能有,不过也来凑热闹


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-06-25 16:44
快速回复:关于教室的人气及发展的讨论
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014842 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved