Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
4120 | 王乾源 | 统计字符串 | C++ | Accepted | 0 MS | 480 KB | 564 | 2020-12-20 21:12:23 |
#include<stdio.h> int letter, digit, space, others; void CountChar(char str[]) { int i; for (i = 0; str[i] != '\0'; i++) { //统计字母 if ((str[i] >= 'a'&& str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) letter++; else if (str[i] >= '0' && str[i] <= '9') //统计数字 digit++; else if (str[i] == ' ')//统计空格 space++; else others++; //统计其他字符 } } int main() { char text[80]; gets(text); CountChar(text); printf("%d %d %d %d", letter, digit, space, others); return 0; }