#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; }
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 人评分
C语言训练-斐波纳契数列 (C语言代码)浏览:820 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:588 |
Hello, world! (C语言代码)浏览:1304 |
时间转换 (Java代码)浏览:609 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:559 |
Pascal三角 (C语言代码)格式错误浏览:549 |
C语言程序设计教程(第三版)课后习题5.7 (Java代码)浏览:906 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:855 |
简单的a+b (C语言代码)浏览:865 |
【蟠桃记】 (C语言代码)浏览:1077 |