04 计算平台数

来源:互联网 发布:php 没有soapclient 编辑:程序博客网 时间:2024/05/16 01:37

数字平台:已知一个有序的数组a,其中有n个元素,n为整数,a中相同的元素构成一个平台,求出a中的最大平台

例如 : “1231”, 第一个1 和最后一个1构成一个平台, 2为一个平台, 3为一个平台, 最大平台为存在两个元素的”1”

参考代码

assume cs:code, ds:data, ss:stackdata segment     notice  db ' *****welcome***** ', 0dH, 0aH, ' please input a string : $ '          ; the memory to save notice information    count   db 16 dup (0)           ; the memory to save every alphabet's tot information    buffer  db 16                   ; the memory to save the input information, the first byte is the capacity of buffer, the second save the count of user inputed, the next 16 byte save the information user inputed            db 0            db 16 dup (0)    result  db 0dH, 0aH, 64 dup (0), ' $ ' ; the memory to save the result informationdata endsstack segment    db 128 dup (0)stack endscode segmentstart:        mov ax, data                ; initialization the ds, ss register        mov ds, ax        mov ax, stack        mov ss, ax        lea dx, notice              ; output notice information        mov ah, 9        int 21H        lea dx, buffer              ; let user to input         mov ah, 10        int 21H        mov cl, ds:[buffer+1]       ; get the nunber user input         mov ch, 0        call analysisNums           ; analysis the count every alphabet appeared        call getMaxInputed          ; calcute the max number in 'count' memory        call putResultsIntoMemory   ; to put the result information into memory        lea dx, result              ; output the result information        mov ah, 9        int 21H        mov ax, 4c00H               ; exit to command line        int 21HputResultsIntoMemory proc near      ; to put the result information into memory        push si        push cx        push ax        mov si, 0        mov di, 2        mov cx, 16        putResultsIntoMemoryLoop1:            cmp dl, ds:[count+si]            jnz putResultsIntoMemoryLoop1End        ; judge if 'ds:[count+si]' is the max value            mov al, dl                  ; if  itis            mov ah, 0            call getAsciiFromNum        ; get the ascii code of it appeard count            mov ds:[result+di], al            mov ds:[result+di+1], 0aH   ; write break line symbol             mov ds:[result+di+2], 0dH            add di, 3            push cx            mov cl, dl            mov ch, 0            mov ax, si            mov ah, 0            call getAsciiFromNum        ; get the nunber of max appeared            outputStringToMemory:       ; repeat 'dl' times to output on cmd            mov ds:[result+di], al            inc di            loop outputStringToMemory            pop cx            mov ds:[result+di], 0aH            mov ds:[result+di+1], 0dH            add di, 2            putResultsIntoMemoryLoop1End:            inc si        loop putResultsIntoMemoryLoop1        pop ax        pop cx        pop si        retputResultsIntoMemory endp       getAsciiFromNum proc near           ; get ascii from a number, or a~f, [0-9a~f]            cmp al, 9            ja getAsciiFromNumFlag1                 add al, 48                  ; 0-9            jmp getAsciiFromNumFlag1End            getAsciiFromNumFlag1:               add al, 87                  ; a-f            getAsciiFromNumFlag1End:            retgetAsciiFromNum endp            getMaxInputed proc near             ; get the max count alphabet had appeared        push cx        push si        mov dl, ds:[count]        mov cx, 15        mov si, 1        getMaxInputedLoop1:            mov dh, ds:[count+si]            cmp dl, dh            ja biggerThan            mov dl, dh            biggerThan:             ; present dl's value is bigger than 'ds:[count+si]'            inc si        loop getMaxInputedLoop1        pop si        pop cx        retgetMaxInputed endpanalysisNums proc near          ; this process is to analysis the data user input, record which alphabet be inputed how many times        push cx        push ax        push si        mov si, 2        analysisNumsLoop1:            mov al, ds:[buffer+si]                call analysisNumsDetail            inc si        loop analysisNumsLoop1        pop si        pop ax        pop cx        retanalysisNums endp       analysisNumsDetail proc near            ; the number need to be judge saved in al        push si        cmp al, 57        ja nums                 cmp al, 48        jb  analysisNumsDetailEnd                                        ; 0-9        sub al, 48        mov ah, 0        mov si, ax        inc ds:[count+si]        jmp analysisNumsDetailEnd    nums:                               ; a-f        cmp al, 97        jb analysisNumsDetailEnd        cmp al, 102        jb analysisNumsDetailEnd        sub al, 87        mov ah, 0        mov si, ax        inc ds:[count+si]    analysisNumsDetailEnd:        pop si        retanalysisNumsDetail endp     code endsend start                ; made by 970655147     2014.07.27

效果截图 : 这里写图片描述

0 0
原创粉丝点击