我的代码工作正常并显示最大出现字符的数量但不显示最大字符。 还告诉我编写代码的聪明方法我是初学者
let notificationMessage = "Beacon button clicked"
let notification = UILocalNotification()
notification.alertBody = notificationMessage
notification.alertAction = "OK"
UIApplication.shared.presentLocalNotificationNow(notification)
}
答案 0 :(得分:0)
你只需要一个额外的
.model small
.stack 100h
.data
msg1 db " <-- Non alpha!$"
msg2 db "Bye!$"
.code
start:
; display ?
mov dl, "?" ; copy ? to dl
mov ah, 2h ; display subprogram
int 21h ; display ?
mov dl, " " ; Provide space
mov ah, 2h ; display subprogram
int 21h
; read character from keyboard
mov ah, 1h ; keyboard input subprogram
int 21h ; read character into al
; save character while we display a Return and Line-feed
cmp al,65d ; 'A'
jb Non_alpha
cmp al,90d ; 'Z'
ja above_alpha_upper
mov bl, al ; save character in bl
add bl,32d ; ADD 32 decimal
mov dl, bl ; copy character to dl
mov ah, 2h ; display subprogram
int 21h ; display character in dl
jmp x
Non_alpha:
mov ax, @data
mov ds,ax
mov dx,offset msg1
mov ah,9h
int 21h
jmp x ; je,ja, jb
above_alpha_upper:
cmp al,97d ; 'a'
jb Non_alpha
cmp al,122d ; 'z'
ja Non_alpha
mov bl, al ; save character in bl
sub bl,32d ; SUBTRACT 32 decimal
mov dl, bl ; copy character to dl
mov ah, 2h ; display subprogram
int 21h ; display character in dl
x: ; exit
mov dl, 13d ; dl = CR, Dh
mov ah, 2h ; display subprogram
int 21h ; display CR
; display Line-feed
mov dl, 10d ; dl = LF , Ah
mov ah, 2h ; display subprogram
int 21h ; display LF
; display character read from keyboard
mov ax, @data
mov ds,ax
mov dx, offset msg2 ; Bye
mov ah,9h
int 21h
mov ax, 4c00h ; return to ms-dos
int 21h
end start
答案 1 :(得分:0)
只需更改将字符保存到
的行 max_occ = (char) i;
索引是字符的代码,asc
中的值是该字符的计数。
你的代码的变量名有点难以理解,也许好一点(恕我直言):
final int MAX = 255;
int[] count = new int[MAX];
char maxChar = ...
int maxCount = -1;
按照惯例,和变量以小写,类和接口名称开头,大写......
答案 2 :(得分:0)
你可以在同一个第一个循环中捕获它
for (int i=0; i<n; i++)
if (++asc[Chars[i]] > max_occ) {
++max_occ;
max_char = Chars[i];
}