人才而已


私信TA

用户名:dotcpp0659034

访问量:624

签 名:

等  级
排  名 15809
经  验 784
参赛次数 0
文章发表 22
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

一、解题思路:

C参考代码:

#include <stdio.h>
#include <string.h>

int main() {
	char str[200];
	int z = 0, s = 0, k = 0, q = 0;
	gets(str);
	for (int i = 0; i < strlen(str); i++) {
		if (('a' <= str[i] && str[i] <= 'z') || ('A' <= str[i] && str[i] <= 'Z')) {
			z++;
		} else if ('0' <= str[i] && str[i] <= '9') {
			s++;
		} else if (str[i] == ' ') {
			k++;
		} else {
			q++;
		}
	}
	printf("%d %d %d %d", z, s, k, q);
	return 0;
}

Java参考代码:

import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		int z=0,s=0,k=0,q=0;
		Scanner sc=new Scanner(System.in);
		String c=sc.nextLine();
		char[] str=c.toCharArray();
		for(int i=0;i<=str.length-1;i++) {
			if(Character.isLetter(str[i])) {
				z++;
			}else if(Character.isDigit(str[i])) {
				s++;
			}else if(Character.isSpaceChar(str[i])) {
				k++;
			}else {
				q++;
			}
		}
		System.out.println(z+" "+s+" "+k+" "+q);
	}
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区