您的位置:程序门 -> vb -> 基础类



一个软件公司面试题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


一个软件公司面试题
发表于:2007-07-12 17:40:26 楼主
两个text(text1,text2),和一个command1
我text1输入一些字符包括数字==
然后单击command1
要在text2显示
(text1取得每个字符的ascii,从小到大依次排序)
比如在text1输入aa1,单击command1
text2显示出     1aa  
发表于:2007-07-12 19:52:301楼 得分:0
private   sub   command1_click()
if   len(text1.text) <=0   then
exit   sub
end   if

dim   nsize   as   integer,i   as   integer,j   as   integer,bchanged   as   boolean
nsize   =   len(text1.text)
dim   atmp(nsize-1)   as   integer

for   i=0   to   ubound(atmp)
' 赋值
atmp(i)   =   asc(mid(text1.text,i,1))

next   i

'冒泡排序
for   i   =   0   to   ubound(atmp)   -1
bchanged   =   false
for   j=0   to   ubound(atmp)-i
if(atmp(j)   >   atmp(j+1))   then
dim   ntmp   as   integer
ntmp=atmp(j+1)
atmp(j+1)   =   atmp(j)
atmp(j)   =   ntmp
bchanged   =   true
end   if
next   j
if   bchanged   =   false   then
exit   for
end   if
next   i

' 在text2中显示处理好以后的数据,按asc从小到大输出;
for   i   =   0   to   ubound(atmp)
text2.text   =   text2.text   &   chr(atmp(i))
next   i
end   sub


没vb6在手上,没测试
发表于:2007-07-12 21:00:082楼 得分:0
private   sub   command1_click()
dim   t1%
t1   =   len(text1.text)
for   i   =   1   to   t1
text2.text   =   mid$(text1.text,   i,   1)   +   text2.text
next
end   sub
发表于:2007-07-13 10:25:023楼 得分:0
to:   zhzboy()   (   )   信誉:100         blog       加为好友     2007-7-12   19:52:30     得分:   0    

你的代码好象不对哦
测试不通过....不过也谢谢你
--------------------------
to:   bfblang()   (   )   信誉:100         blog       加为好友     2007-7-12   21:00:08     得分:   0    
        你的代码...........
发表于:2007-07-13 10:32:314楼 得分:0
private   sub   command1_click()
        dim   szstr   as   string
        dim   inti   as   integer
        dim   icnt   as   integer
        dim   arry()   as   string
        szstr   =   text2.text
        inti   =   len(szstr)
       
        for   icnt   =   0   to   len(szstr)   -   1
                redim   preserve   arry(icnt)
                arry(icnt)   =   asc(mid(szstr,   icnt   +   1,   1))
        next   icnt
       
        call   quicksort(arry(),   0,   ubound(arry))
        szstr   =   " "
        for   icnt   =   0   to   ubound(arry)
                szstr   =   szstr   &   chr(arry(icnt))
                 
        next   icnt
       
        text2.text   =   szstr
       
end   sub

sub   quicksort(marry()   as   string,   l   as   integer,   r   as   integer)
        dim   i   as   integer,   j   as   integer,   x   as   integer,   y   as   integer
        i   =   l
        j   =   r
        x   =   marry((l   +   r)   /   2)
        while   (i   <=   j)
                while   (marry(i)   <   x   and   i   <   r)
                        i   =   i   +   1
                wend
               
                while   (x   <   marry(j)   and   j   >   l)
                      j   =   j   -   1
                wend
               
                if   (i   <=   j)   then
                        y   =   marry(i)
                        marry(i)   =   marry(j)
                        marry(j)   =   y
                        i   =   i   +   1
                        j   =   j   -   1
                end   if
        wend
       
        if   (l   <   j)   then   call   quicksort(marry(),   l,   j)
        if   (i   <   r)   then   call   quicksort(marry(),   i,   r)
       
       

end   sub
发表于:2007-07-13 10:59:005楼 得分:0
我的咋了?简单实用,用最少的代码完成任务不久行了嘛?
发表于:2007-07-13 11:04:116楼 得分:0
private   sub   command1_click()
dim   i%
for   i   =   1   to   len(text1.text)
text2.text   =   mid$(text1.text,   i,   1)   +   text2.text
next
end   sub
太复杂了,我一直想学
发表于:2007-07-13 13:27:167楼 得分:0
在form中添加listbox,listbox的sorted属性设为true
private   sub   command1_click()
text2.text   =   " "
list1.clear
dim   i   as   integer
for   i   =   1   to   len(text1.text)
        list1.additem   mid(text1.text,   i,   1)
next   i
for   i   =   0   to   list1.listcount   -   1
        text2.text   =   text2.text   &   list1.list(i)
next   i

end   sub不知是这意思吗?
发表于:2007-07-13 13:51:138楼 得分:0
private   sub   command1_click()
      dim   my_n(),   my_w(),   my_flg()
      dim   i   as   long,   j   as   long,   cc   as   long
      redim   my_n(1   to   len(text1.text))
      redim   my_w(1   to   len(text1.text))
      redim   my_flg(1   to   len(text1.text))
      text2.text   =   " "
      for   i   =   1   to   len(text1.text)
            my_n(i)   =   asc(mid(text1.text,   i,   1))
            my_flg(i)   =   true
      next
      cc   =   1
      i   =   1
g_next:   do   while   i   <=   len(text1.text)
            if   my_flg(i)   =   false   then   i   =   i   +   1:   goto   g_next
            min_n   =   my_n(i)
            rr   =   i
            for   j   =   1   to   len(text1.text)
                  if   min_n   >   my_n(j)   and   my_flg(j)   =   true   then   rr   =   j:   min_n   =   my_n(j)
            next
            my_w(cc)   =   min_n
            my_flg(rr)   =   false
            cc   =   cc   +   1
      loop
      for   i   =   1   to   len(text1.text)
            text2.text   =   text2.text   &   chr(my_w(i))
      next
end   sub
发表于:2007-07-13 15:19:249楼 得分:0
private   sub   command1_click()
        dim   s
        text2.text   =   " "
        dim   t1
        t1   =   text1.text
        dim   i
        for   i   =   1   to   len(t1)
                s   =   mid(t1,   i,   1)
                dim   ipos
                ipos   =   i
                dim   j
                for   j   =   i   +   1   to   len(t1)
                        if   mid(t1,   j,   1)   <   s   then
                                s   =   mid(t1,   j,   1)
                                ipos   =   j
                        end   if
                next
                dim   tt1
                tt1   =   left(t1,   i   -   1)   &   s
                if   ipos   >   i   then
                        tt1   =   tt1   &   mid(t1,   i   +   1,   ipos   -   i   -   1)   &   mid(t1,   i,   1)
                end   if
                tt1   =   tt1   &   right(t1,   len(t1)   -   ipos)
                t1   =   tt1
                text2.text   =   text2.text   &   s
        next
       
end   sub
发表于:2007-07-13 15:37:5510楼 得分:0
'这个方法也可以

private   sub   command1_click()
 
        text2.text   =   resetarr(text1.text)
       
end   sub

function   resetarr(byval   s   as   string)   as   string
        dim   arr()
        redim   preserve   arr(len(s)   -   1)
        dim   i
        for   i   =   1   to   len(s)
                arr(i   -   1)   =   mid(s,   i,   1)
        next
       
        for   i   =   0   to   ubound(arr)
                s   =   arr(i)
                dim   ipos
                ipos   =   i
                dim   j
                for   j   =   i   +   1   to   ubound(arr)
                        if   arr(j)   <   s   then
                                s   =   arr(j)
                                ipos   =   j
                        end   if
                next
                arr(ipos)   =   arr(i)
                arr(i)   =   s
        next
        s   =   " "
        for   i   =   0   to   ubound(arr)
                s   =   s   &   arr(i)
        next
        resetarr   =   s
end   function
发表于:2007-07-13 16:26:1411楼 得分:0
如果只包含英文字符和数字,还可以这样
不需要排序,但是效率不高
private   sub   command1_click()
        dim   arr(1   to   128)   as   long
        dim   i   as   long,   nasc   as   long
        dim   s   as   string
        s   =   text1.text
        for   i   =   1   to   len(s)
                nasc   =   asc(mid(s,   i,   1))
                arr(nasc)   =   arr(nasc)   +   1
        next
        s   =   " "
        for   i   =   1   to   128
                s   =   s   &   string(arr(i),   chr(i))
        next
        text2.text   =   s
end   sub
发表于:2007-07-13 19:49:3712楼 得分:0
private   sub   command1_click()
        text2.text   =   " "
        if   len(text1.text)   <=   0   then
                exit   sub
        end   if

        dim   nsize   as   integer,   i   as   integer,   j   as   integer,   bchanged   as   boolean,   atmp()   as   integer
        nsize   =   len(text1.text)
        redim   atmp(nsize   -   1)   as   integer

        for   i   =   0   to   ubound(atmp)
                '赋值
                atmp(i)   =   asc(mid(text1.text,   i   +   1,   1))
       
        next   i

        '冒泡排序
        for   i   =   1   to   ubound(atmp)
                bchanged   =   false
                for   j   =   0   to   ubound(atmp)   -   i
                        if   (atmp(j)   >   atmp(j   +   1))   then
                                dim   ntmp   as   integer
                                ntmp   =   atmp(j   +   1)
                                atmp(j   +   1)   =   atmp(j)
                                atmp(j)   =   ntmp
                                bchanged   =   true
                        end   if
                next   j
                if   bchanged   =   false   then
                        exit   for
                end   if
        next   i

'在text2中显示处理好以后的数据,按asc从小到大输出;
for   i   =   0   to   ubound(atmp)
        text2.text   =   text2.text   &   chr(atmp(i))
next   i
end   sub


测试了,改了,这个可行
发表于:2007-07-14 21:04:2613楼 得分:0
这个软件公司很强。要求算法层面的技术人员。

哈哈哈,一定是开发后台程序的。

虽然冒泡最基础,但是可以发明他的人智商也是万里挑一的。
发表于:2007-07-15 02:07:4914楼 得分:0
好象有个内部函数可以直接输入相反的东西哦.
发表于:2007-07-15 10:32:2015楼 得分:0
学习了
发表于:2007-08-04 16:03:0816楼 得分:0
谢谢各位了...
zhzboy()   (   )   信誉:100


快速检索

最新资讯
热门点击