#include<stdio.h> void main() { char a[256]; int i,n1,n2,n3,n4; gets(a); for ( i=n1=n2=n3=n40;i<20;i++ ) if ( a[i]==' ' ) n1++; else if ( (a[i]>='0')&&(a[i]<='9') ) n2++; else if ( (a[i]>='a' && a[i]<='z')||(a[i]>='A' && a[i]<='Z') ) n3++; else n4++; printf("英文字符个数%d,空格数%d,数字字符个数%d,其他字符%d\n",n3,n1,n2,n4); }
相思故
2024-06-06 04:30:30
class Program { static void Main(string[] args) { string[] temp = new string[20]; for (int i = 0; i < temp.Length; i++) { temp[i] = Console.ReadLine(); } int letter = 0; int number = 0; int space = 0; int more = 0; foreach (string str in temp) { if (Regex.IsMatch(str, "[a-zA-Z]")) { letter += 1; } else if (Regex.IsMatch(str,"[0-9]")) { number += 1; } else if (Regex.IsMatch(str," ")) { space += 1; } else { more += 1; } } Console.WriteLine("英文字符:{0}个,空格字符:{1}个,数字字符:{2}个,其他字符:{3}个", letter,space,number,more); Console.ReadKey(); } }
安七
2024-06-06 08:24:02
#include<stdio.h> void main() { char a[256]; int i,n1,n2,n3,n4; gets(a); for ( i=n1=n2=n3=n40;i<20;i++ ) if ( a[i]==' ' ) n1++; else if ( (a[i]>='0')&&(a[i]<='9') ) n2++; else if ( (a[i]>='a' && a[i]<='z')||(a[i]>='A' && a[i]<='Z') ) n3++; else n4++; printf("英文字符个数%d,空格数%d,数字字符个数%d,其他字符%d\n",n3,n1,n2,n4); }