基本思想
从欲求解的原问题出发,运用科学抽象的方法,把它分解成若干相对独立的小问题,依次细化,直至各个小问题获得解决为止。
求精技术
如图
求精技术包含: 顺序连接的求精、分支和选择的求精、循环的求精、递归的求精
实例
洗衣机:
将问题分解为:1.接通电源,打开洗衣机,放入衣物 2.选择水量,洗衣模式 3.打开水龙头,接入水源 4.开始洗涤 5.洗涤完毕,提示断开电源
伪代码:
plug in //接通电源
open the washer //打开洗衣机
choose how much water // 选择水量
put in clothes // 放入衣物
/*
洗涤
*/
begin choose mode // 选择模式
if choose 快速洗
then turn on the switch //接入水源
input water //注水
turn off the switch//停止注水
start //开始
while(time <= 5min)
do wash //洗涤
end
output//排水
if choose 标准洗
then turn on the switch //接入水源
input water //注水
turn off the switch//停止注水
start //开始
while(time <= 10min)
do wash //洗涤
end
output//排水
if choose 强力洗
then turn on the switch //接入水源
input water //注水
turn off the switch//停止注水
start //开始
while(time <= 15min)
do wash //洗涤
end
output//排水
end
/*
脱水
*/
while(time <= 5min)
do 滚筒旋转,脱水
end
/*
结束
*/
ring//提示 turn off//关闭