输入两个字符串s1,s2,将两个字符串连接起来并复制到字符串s3中,统计s3中的每个数字的个数,大写字母的个数,小写字母的个数和其他字符的个数的C语言
时间: 2024-05-06 21:14:54 浏览: 84
JavaScript自定义函数实现查找两个字符串最长公共子串的方法
实现如下:
```c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char s1[100], s2[100], s3[200];
int i, digit_count = 0, upper_count = 0, lower_count = 0, other_count = 0;
printf("Enter string s1: ");
fgets(s1, sizeof(s1), stdin);
s1[strcspn(s1, "\n")] = '\0'; // remove newline character
printf("Enter string s2: ");
fgets(s2, sizeof(s2), stdin);
s2[strcspn(s2, "\n")] = '\0'; // remove newline character
strcpy(s3, s1);
strcat(s3, s2);
for (i = 0; s3[i] != '\0'; i++) {
if (isdigit(s3[i])) {
digit_count++;
} else if (isupper(s3[i])) {
upper_count++;
} else if (islower(s3[i])) {
lower_count++;
} else {
other_count++;
}
}
printf("s3: %s\n", s3);
printf("Number of digits: %d\n", digit_count);
printf("Number of uppercase letters: %d\n", upper_count);
printf("Number of lowercase letters: %d\n", lower_count);
printf("Number of other characters: %d\n", other_count);
return 0;
}
```
输入示例:
```
Enter string s1: Hello
Enter string s2: 123world!
s3: Hello123world!
Number of digits: 3
Number of uppercase letters: 1
Number of lowercase letters: 8
Number of other characters: 1
```
阅读全文