| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 733 人关注过本帖
标题:如何用程序选择符合条件的数据
只看楼主 加入收藏
xwcj
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-9-8
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:12 
如何用程序选择符合条件的数据
从0000至9999一万组四位数中选出(含1或4或7且任二位数和等0或6或8)的数据。例0001就符合条件,而0005就不符合
搜索更多相关主题的帖子: 如何 如何 
2011-09-08 11:41
寻H不得
Rank: 4
等 级:业余侠客
威 望:1
帖 子:181
专家分:222
注 册:2010-10-9
收藏
得分:0 
题意不清楚
1.是选出全部还是随机选出一个?
2.含1或4或7且任二位数和等0或6或8 是如何理解?是 含1或4或 (7且任二位数和等0或6或8)还是 (含1或4或7)且任二位数和等0或6或8

至于从0000至9999选数并判断 到不是多大问题的
我见过这样做的(全部数列) 可作参考:
 for I=1 to 10000
   x=subst(allt(str(10000+I)),2,4)  &&生成0000-9999的文本数据
     if '1'$x or '4'$X or '7'$X ......    &&条件判断 省略号是你的准确条件
       ?X                                 &&显示符合条件的数列 或其它处理
     endif   
 endfor
2011-09-08 12:57
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
回复 2楼 寻H不得
你没看清楚他的问题吧?再看看,呵呵~

授人以渔,不授人以鱼。
2011-09-08 13:37
xwcj
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-9-8
收藏
得分:0 
问题一,是全部选出
问题二,就是一万个四位数里只要含有一个(1或4或7)就行,并且有二数和等于(0或6或8)就行
举例:符合条件的5057(5+5=0,含有7) 1000 (0+0=0,含有1)8403 (8+0=8,含有4)
不符合条件的0005(0+0=0,但没含有1,4,7)5678(5+6=1,5+7=2,5+8=3,6+7=3,6+8=4,7+8=5,都没有符合二数和等于0,6,8,)
2011-09-08 14:52
muyubo
Rank: 9Rank: 9Rank: 9
来 自:山东莱芜
等 级:蜘蛛侠
威 望:3
帖 子:471
专家分:1017
注 册:2011-3-6
收藏
得分:0 
干么用啊?这么复杂.
2011-09-08 17:05
scilent
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:285
专家分:1399
注 册:2011-8-9
收藏
得分:0 
4578个
SET TALK OFF
CLEAR ALL
lncounter=0
FOR start=0 TO 9999
    lcNumber=SUBSTR(ALLTRIM(STR(start)),1,4)
    lnLength=Len(lcNumber)
    DO CASE
        CASE lnlength=1 OR lnLength=2
            IF lcNumber="1" OR lcNumber="4" OR lcNumber="7"
                 ?? lcNumber
                 lncounter=lncounter+1
            ENDIF
        CASE lnLength=3
            IF "1"$lcNumber OR "4"$lcNumber OR "7"$lcNumber
            lcNumOne=SUBSTR(lcNumber,1,1)
            lcNumTwo=SUBSTR(lcNumber,2,1)
            lcNumThr=SUBSTR(lcNumber,3,1)
            lnSum1=VAL(lcNumOne)+VAL(lcNumTwo)
            lnSum2=VAL(lcNumOne)+VAL(lcNumThr)
            lnSum3=VAL(lcNumThr)+VAL(lcNumTwo)
            DO CASE
                Case lnSum1=10 OR lnSum1=16 OR lnSum1=18
                     ??lcNumber
                     lncounter=lncounter+1
                CASE lnSum2=10 OR lnSum2=16 OR lnSum2=18
                    ??lcNumber
                    lncounter=lncounter+1
                CASE lnSum3=10 OR lnSum3=16 OR lnSum3=18
                    ??lcNumber
                    lncounter=lncounter+1
                CASE lcNumOne="0" OR lcNumTwo="0" OR lcNumThr="0"
                    ??lcNumber
                    lncounter=lncounter+1
             ENDCASE
             ENDIF  
        CASE lnLength=4
            IF "1"$lcNumber OR "4"$lcNumber OR "7"$lcNumber
            lcNumOne=SUBSTR(lcNumber,1,1)
            lcNumTwo=SUBSTR(lcNumber,2,1)
            lcNumThr=SUBSTR(lcNumber,3,1)
            lcNumFou=SUBSTR(lcNumber,4,1)
            lnSum1=VAL(lcNumOne)+VAL(lcNumTwo)
            lnSum2=VAL(lcNumOne)+VAL(lcNumThr)
            lnSum3=VAL(lcNumThr)+VAL(lcNumTwo)
            lnSum4=VAL(lcNumThr)+VAL(lcNumFou)
            lnSum5=VAL(lcNumTwo)+VAL(lcNumFou)
            lnSum6=VAL(lcNumOne)+VAL(lcNumFou)
            DO CASE
                Case lnSum1=10 OR lnSum1=16 OR lnSum1=18 OR lnsum1=0
                     ??lcNumber
                     lncounter=lncounter+1
                CASE lnSum2=10 OR lnSum2=16 OR lnSum2=18 OR lnsum2=0
                    ??lcNumber
                    lncounter=lncounter+1
                CASE lnSum3=10 OR lnSum3=16 OR lnSum3=18 OR lnsum3=0
                    ??lcNumber
                    lncounter=lncounter+1
                CASE lnSum4=10 OR lnSum4=16 OR lnSum4=18 OR lnsum4=0
                    ??lcNumber
                    lncounter=lncounter+1
                CASE lnSum5=10 OR lnSum5=16 OR lnSum5=18 OR lnsum5=0
                    ??lcNumber
                    lncounter=lncounter+1
                CASE lnSum6=10 OR lnSum6=16 OR lnSum6=18 OR lnsum6=0
                    ??lcNumber
                    lncounter=lncounter+1
            ENDCASE
            ENDIF
    ENDCASE
    ENDFOR
?? lncounter
SET TALK ON
我有事走了,你再改改

在没有路的地方走一条路,让别人有路可走
2011-09-08 17:29
茵梦湖
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:31
帖 子:545
专家分:2180
注 册:2009-4-25
收藏
得分:0 

clea
lsn=0
for kk=0 to 9999
    kkc =padl(kk,4,"0")
    ls和 =tran(int(val(left(kkc,1))+val(subs(kkc,2,1)))%10);
         +tran(int(val(left(kkc,1))+val(subs(kkc,3,1)))%10);
         +tran(int(val(left(kkc,1))+val(subs(kkc,4,1)))%10);
         +tran(int(val(subs(kkc,2,1))+val(subs(kkc,3,1)))%10);
         +tran(int(val(subs(kkc,2,1))+val(subs(kkc,4,1)))%10);  
         +tran(int(val(subs(kkc,3,1))+val(subs(kkc,4,1)))%10)
    if ( "1"$kkc .or."4"$kkc .or."7"$kkc ) .and.( "0"$ls和 .or."6"$ls和 .or."8"$ls和 )
       ?? kkc+"  "
       lsn =lsn+1
    endif
endfor
?"  计( " +tran(lsn) +" )个"
retu
2011-09-08 17:58
scilent
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:285
专家分:1399
注 册:2011-8-9
收藏
得分:18 
大侠,太佩服了,看来代码不是重在写,是重在考虑
我看看自己的,把错的地方改了,可是还是不对,请大家帮我看看
SET TALK OFF
CLEAR ALL
lncounter=0
FOR start=0 TO 9999
    lcNumber=SUBSTR(ALLTRIM(STR(start)),1,4)
    lnLength=Len(lcNumber)
    DO CASE
        CASE lnlength=1 OR lnLength=2
            IF "1"$lcNumber OR "4"$lcNumber OR "7"$lcNumber
                ??lcnumber+" "
                lncounter=lncounter+1
            ENDIF
        CASE lnLength=3
            IF "1"$lcNumber OR "4"$lcNumber OR "7"$lcNumber
            lcNumOne=SUBSTR(lcNumber,1,1)
            lcNumTwo=SUBSTR(lcNumber,2,1)
            lcNumThr=SUBSTR(lcNumber,3,1)
            lnSum1=VAL(lcNumOne)+VAL(lcNumTwo)
            lnSum2=VAL(lcNumOne)+VAL(lcNumThr)
            lnSum3=VAL(lcNumThr)+VAL(lcNumTwo)
            DO CASE
                Case lnSum1=10 OR lnSum1=16 OR lnSum1=18 OR lnsum1=6 OR lnsum1=8
                     ??lcnumber+" "
                     lncounter=lncounter+1
                CASE lnSum2=10 OR lnSum2=16 OR lnSum2=18 OR lnsum2=6 OR lnsum2=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lnSum3=10 OR lnSum3=16 OR lnSum3=18 OR lnsum3=6 OR lnsum3=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lcNumOne="0" OR lcNumTwo="0" OR lcNumThr="0"
                    ??lcnumber+" "
                    lncounter=lncounter+1
             ENDCASE
             ENDIF  
        CASE lnLength=4
            IF "1"$lcNumber OR "4"$lcNumber OR "7"$lcNumber
            lcNumOne=SUBSTR(lcNumber,1,1)
            lcNumTwo=SUBSTR(lcNumber,2,1)
            lcNumThr=SUBSTR(lcNumber,3,1)
            lcNumFou=SUBSTR(lcNumber,4,1)
            lnSum1=VAL(lcNumOne)+VAL(lcNumTwo)
            lnSum2=VAL(lcNumOne)+VAL(lcNumThr)
            lnSum3=VAL(lcNumThr)+VAL(lcNumTwo)
            lnSum4=VAL(lcNumThr)+VAL(lcNumFou)
            lnSum5=VAL(lcNumTwo)+VAL(lcNumFou)
            lnSum6=VAL(lcNumOne)+VAL(lcNumFou)
            DO CASE
                Case lnSum1=10 OR lnSum1=16 OR lnSum1=18 OR lnsum1=0 OR lnsum1=6 OR lnsum1=8
                     ??lcnumber+" "
                     lncounter=lncounter+1
                CASE lnSum2=10 OR lnSum2=16 OR lnSum2=18 OR lnsum2=0 OR lnsum2=6 OR lnsum2=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lnSum3=10 OR lnSum3=16 OR lnSum3=18 OR lnsum3=0 OR lnsum3=6 OR lnsum3=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lnSum4=10 OR lnSum4=16 OR lnSum4=18 OR lnsum4=0 OR lnsum4=6 OR lnsum4=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lnSum5=10 OR lnSum5=16 OR lnSum5=18 OR lnsum5=0 OR lnsum5=6 OR lnsum5=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lnSum6=10 OR lnSum6=16 OR lnSum6=18 OR lnsum6=0 OR lnsum6=6 OR lnsum6=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
            ENDCASE
            ENDIF
    ENDCASE
    ENDFOR
    ??"共计有("+TRANSFORM(lncounter)+")个"
SET TALK ON

在没有路的地方走一条路,让别人有路可走
2011-09-08 21:44
茵梦湖
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:31
帖 子:545
专家分:2180
注 册:2009-4-25
收藏
得分:2 
回复 8楼 scilent

有句代码改为如下(红字部分)即可~  比如116,118,136,138...之类是满足条件的, 但在你的8楼程序中 并没有计入~
 
 

        CASE lnLength=3
           ....
           ....
            DO CASE
                Case lnSum1=10 OR lnSum1=16 OR lnSum1=18 OR lnsum1=6 OR lnsum1=8
                     ??lcnumber+" "
                     lncounter=lncounter+1
                CASE lnSum2=10 OR lnSum2=16 OR lnSum2=18 OR lnsum2=6 OR lnsum2=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lnSum3=10 OR lnSum3=16 OR lnSum3=18 OR lnsum3=6 OR lnsum3=8
                    ??lcnumber+" "
                    lncounter=lncounter+1
                CASE lcNumOne$"068" .or.lcNumTwo$"068" .or.lcNumThr$"068"
                    ??lcnumber+" "
                    lncounter=lncounter+1
             ENDCASE

2011-09-09 00:07
scilent
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:285
专家分:1399
注 册:2011-8-9
收藏
得分:0 
哦,是啊,我看了几次都没看出来,谢谢大侠

在没有路的地方走一条路,让别人有路可走
2011-09-09 09:44
快速回复:如何用程序选择符合条件的数据
数据加载中...
 
   



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

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