This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
#include<bits/stdc++.h>
using namespace std;
#define MAX 1024
void cal_num(char *str, int count[]) {
char *pstr;
pstr=str;
while(*pstr) { /* *pstr != 0 */
if(*pstr>='0' && *pstr<='9')
count[0]++;
else if((*pstr>='a' && *pstr<='z') || (*pstr>='A' && *pstr<='Z'))
count[1]++;
else
count[2]++;
pstr++;
}
}
int main() {
char str[MAX];
int i, count[3]; /* 0->num; 1->char; 2->others */
memset(count, 0, 3*sizeof(int));
printf("Enter a string: ");
//scanf("%s", str);
scanf("%[^\n]",str); //<2F><><EFBFBD><EFBFBD>'\n'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
cal_num(str, count);
for(i=0; i<3; i++) {
switch(i) {
case 0:
printf("num: %d\n", count[i]);
break;
case 1:
printf("char: %d\n", count[i]);
break;
case 2:
printf("other: %d\n", count[i]);
break;
}
}
return 0;
}