统计字符串中英文字母的个数(指针)

描述

键盘输入一行字符,统计该字符串中英文字母的个数。设计一个函数:‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

int fun8(char *s);

该函数的功能是统计字符串 s 中英文字母的个数。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

裁判测试程序样例:

#include <stdio.h>
#include <string.h>
int fun8(char *s);

int main() {
	char s[100];
	int count;
	/* Input */
	gets(s);
	/* Calculate */
	count = fun8(s);
	/* Output */
	printf("count=%d\n", count);
	return 0;
}
/* 你的代码将被嵌在这里 */

输入‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

输入字符串(字符个数<100)。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

输出

输出大写英文字母的个数。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

输入输出示例

‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

输入输出
示例 1
aBc234dEfGh
count=8

 

#include <stdio.h>
#include <string.h>
int fun8(char *s);

int main() {
	char s[100];
	int count;
	/* Input */
	gets(s);
	/* Calculate */
	count = fun8(s);
	/* Output */
	printf("count=%d\n", count);
	return 0;
}
int fun8(char *s)
{
	int longs=0,i;
	for(i=0;s[i]!='\0';i++){
		if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'){
			longs++;
		}
	}
	return longs;
}

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是使用 x86 汇编语言统计字符串英文字母个数的示例代码: ``` section .data str db 'Hello, World!',0 len equ $-str section .text global _start _start: mov ecx, len ; 将字符串长度存储在 ecx mov esi, str ; 将字符串地址存储在 esi xor eax, eax ; 将 eax 清零 xor ebx, ebx ; 将 ebx 清零 count_loop: cmp ecx, 0 ; 判断是否到字符串结尾 je count_done mov al, [esi] ; 将当前字符存储在 al cmp al, 'A' ; 比较字符是否大于等于 'A' jb count_next cmp al, 'Z' ; 比较字符是否小于等于 'Z' ja count_lower inc ebx ; 增加大写字母计数器 jmp count_next count_lower: cmp al, 'a' ; 比较字符是否大于等于 'a' jb count_next cmp al, 'z' ; 比较字符是否小于等于 'z' ja count_next inc ebx ; 增加小写字母计数器 count_next: inc esi ; 增加字符串指针 dec ecx ; 减少字符串长度 jmp count_loop count_done: ; 计数结果存储在 ebx ; 可以进行打印或其他操作 mov eax, 1 ; 调用系统调用 1 (write) mov ebx, 1 ; 将文件描述符存储在 ebx mov ecx, ebx ; 将计数器值存储在 ecx int 0x80 ; 调用系统调用 mov eax, 0 ; 调用系统调用 0 (exit) xor ebx, ebx ; 将返回值存储在 ebx int 0x80 ; 调用系统调用 ``` 该代码将字符串存储在 `.data` 段的 `str` 变量,并将字符串长度存储在 `len` 。`count_loop` 标签处的代码循环遍历字符串的每个字符,并根据字符是否为英文字母来增加计数器。最后,计数结果存储在 `ebx` ,可以进行打印或其他操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张立龙666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值