| Цитата | const StrWithWords: string = 'First Second Third Lake Foot Sand Tread Fake Dust Solid'; NumWords: word = 0; begin asm mov si,offset StrWithWords { bx = string len } mov dl,[si] mov dh,0 { dx = point to last symbol } add dx,si { si = point to first symbol } inc si { cx = number of founded words } xor cx,cx { bx = point to founded first and last symbols } mov bx,si { Store bx } push bx @@FindWords: cmp si,dx jae @@SearchDone { Get first symbol of current word in al } mov al,[si] { Find last symbol in word } mov di,si @@ScanForFiller: inc di cmp di,dx ja @@ScanForFillerDone cmp byte ptr [di],' ' jnz @@ScanForFiller @@ScanForFillerDone: { Get last symbol in ah } mov ah,[di-1] { Store first and last symbol in string } mov word ptr [bx],ax { bx point to next pair } add bx,2 { si = point to next word } lea si,[di+1] { Increment number of words } inc cx jmp @@FindWords @@SearchDone: { bx = point to begin of pairs } pop bx cmp cx,1 jbe @@NoMoreWords dec cx @@ComapreWords: { Get first and last symbols in ax } mov ax,[bx] add bx,2 mov si,bx push cx @@ScanForCurrentPair: cmp word ptr [si],ax jnz @@NoEqualPair inc word ptr NumWords @@NoEqualPair: { si = point to next pair } add si,2 loop @@ScanForCurrentPair pop cx loop @@ComapreWords @@NoMoreWords: end; writeln('Number words = ',NumWords); end.
| Добавлено @ 18:18 Да, и уточни - что делать, если в строке есть три слова типа Ted Tod Tread. |