统计含"a"或者含"A"的字符串个数

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>含a或A的字符</title>
</head>
<body>
<script>
//题目:统计含a 或者含 A 的字符串个数
//script中数组的用()or[]来定义。
var char=new Array("America","Greece","Britain","Canada","Chian","Egypt");
var num=0;
for (var i=0;i<char.length;i++){
//indexOf()方法,返回指定的字符串在字符串中首次出现的索引位置,如果没找到返回 -1 ;
if ((char[i].indexOf("a"||"A"))!=-1){
num++;
}
}
document.write(num);
</script>
</body>
</html>

转载于:https://www.cnblogs.com/taoist123/p/11124794.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个汇编语言程序,用于统计字符串中字符的个数。以下是示例代码: ``` section .data string db 'Hello, world!',0 section .bss count resb 26 section .text global _start _start: xor ecx, ecx ; clear ECX register mov esi, string ; load address of string into ESI register count_loop: mov eax, [esi] ; load next character from string into EAX register cmp eax, 0 ; check if end of string je end_loop cmp eax, 'a' ; check if character is between 'a' and 'z' jl not_lowercase cmp eax, 'z' jg not_lowercase sub eax, 'a' ; convert lowercase character to index inc byte [count + eax] ; increment count for that character not_lowercase: inc esi ; move to next character inc ecx ; increment character count jmp count_loop end_loop: ; print character counts for each lowercase letter mov esi, count mov ecx, 26 print_loop: movzx eax, byte [esi] push eax push dword 'a' mov eax, 4 mov ebx, 1 mov ecx, esp mov edx, 2 int 0x80 add esp, 8 inc esi loop print_loop ; exit program mov eax, 1 xor ebx, ebx int 0x80 ``` 该程序首先定义一个字符串(在`.data`节中),然后在`.bss`节中定义了一个26字节的计数器数组(用于计算每个小写字母的出现次数)。程序使用ECX寄存器计算字符串中的字符总数,并使用ESI寄存器跟踪当前字符的地址。在循环中,程序检查当前字符是否为小写字母,并将其转换为小写字母计数器数组中的索引。然后,程序将该字符的计数器递增,然后移动到下一个字符并重复此过程,直到字符串的结尾。 最后,程序使用`int 0x80`系统调用打印每个小写字母的计数器值,并使用`int 0x80`调用退出程序。 请注意,此示例程序仅计算小写字母的频率,并且假定字符串以null字符结尾。如果您需要计算其他字符的频率,或者字符串以不同的方式终止,请相应地更改程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值