小鸟禽流感症状:什么是枚举法,举个简单的例子看看?pascal

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/05 23:35:00

我举个例给你看
var x,y:integer;
begin
for x:=1 to 100 do
for y:=1 to 100 do
begin
if x+y=100 then writeln ('x=',x,'y',t)
end;
readln
end.

采用枚举法的源程序如下:
<%@ CODEPAGE = "936" %>
'连接数据库
<%
dim conn
dim DBOath
dim rs
dim sql
Set conn=Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("addressbook.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set rs=Server.CreateObject("ADODB.Recordset")
'从Web页获取姓名、电话、学校的值
dim Name
dim Tel
dim School
Name=request("Name")
Tel=request("Tel")
School=request("School")
'枚举法的搜索核心,因为有3个条件所以要写8组If判断语句
if trim(Name)="" and trim(Tel)="" and trim(School)="" then
sql="select * from address order by ID asc"
end if
if trim(Name)="" and trim(Tel)="" and trim(School)<>"" then
sql="select * from address where School like '%"&trim(School)&"%' order by ID asc"
end if
if trim(Name)="" and trim(Tel)<>"" and trim(School)="" then
sql="select * from address where Tel like '%"&trim(Tel)&"%' order by ID asc"
end if
if trim(Name)="" and trim(Tel)<>"" and trim(School)<>"" then
sql="select * from address where Tel like '%"&trim(Tel)&"%' and School like '%"&trim(School)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)="" and trim(School)="" then
sql="select * from address where Name like '%"&trim(Name)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)="" and trim(School)<>"" then
sql="select * from address where Name like '%"&trim(Name)&"%' and School like '%"&trim(School)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)<>"" and trim(School)="" then
sql="select * from address where Name like '%"&trim(Name)&"%' and Tel like '%"&trim(Tel)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)<>"" and trim(School)<>"" then
sql="select * from address where Name like '%"&trim(Name)&"%' and Tel like '%"&trim(Tel)&"%' and School like '%"&trim(School)&"%' order by ID asc"
end if
rs.open sql,conn,1,1
'显示搜索结果
if rs.eof and rs.bof then
response.write "目前通讯录中没有记录"
else
do while not rs.eof
response.write "姓名:"&rs("Name")&"电话:"&rs("Tel")&"学校:"&rs("School")&"<br>"
rs.movenext
loop
end if
'断开数据库
set rs=nothing
conn.close
set conn=nothing
%>

理解上述程序时,着重琢磨核心部分,8组语句一一对应了3个搜索框中的8种状态

Name Tel School
空 空 空
空 空 非空
空 非空 空
空 非空 非空
非空 空 空
非空 空 非空
非空 非空 空
非空 非空 非空

另外trim()是VB的函数,将输入的字符串前后的空格去掉;%是SQL语言中的多字符通配符(_是单字符通配符),由此可见%"&trim()&"%对搜索框中输入的关键字是分别向左向右匹配的;SQL语言中用and连接说明非空条件之间是“与”关系。

我想可能是和穷举差不多吧
var i,a,n:integer
……
……
for i:=1 to n do
begin
if i*i+2a+n=100 then writeln(a,n,i)
我想可能是这样的。

我不会

枚举就是不设定条件来个全遍历

sorry