编写程序。输入一行字符(以回车符结束),分别统计其中字母、数字和其他符号的个数。相关知识点: 试题来源: 解析 解:#include void main() {char str[256],*p;int a,b,c; gets(str);p=str;a=b=c=0; while ( *p ) { if ( (*p)>='A' && (*p)<='Z' ) a++; else if ( (*p)>='a' &&...
编写一段程序,要求输入一行字符,以回车结束,分别统计出其中英文字母、空格、数字和其它字符的个数。相关知识点: 试题来源: 解析 编程方法 有多种,本答案为参考答案: #include void main() { char ch; int letter,space,digit,other; letter=space=digit=other=0; while((ch=getchar())!='\n') { if(...
1. 接收用户输入的字符串,直到遇到回车符为止 在C语言中,我们可以使用getchar()函数来逐字符读取用户输入,直到遇到回车符( )为止。这样,我们就可以获取用户输入的整个字符串。 2. 初始化英文字母、数字字符和其他字符的计数为0 在程序开始时,我们需要初始化三个变量来分别记录英文字母、数字字符和其他字符的个数。
include "stdio.h"main(){char c,sum1=0,sum2=0,space=0,number=0,other=0;c=getchar();while(c!='\n'){ if(c>='A'&&c<='Z') sum1++;else if(c>='a'&&c<='z') sum2++;else if(c>='0'&&c<='9') number++;else if(c==' ') space++;else other ++;c=getcha...
编写程序,输入一个以回车结束的字符串(少于80个字符),统计并输出其中大写辅音字母的个数(大写辅音字母:除'A','E','I','O','U'以外的大写字母)。相关知识点: 试题来源: 解析 #include int main(void) { int count,i; char ch,str[80]; printf("Input a string: "); i=0; while((ch=getchar...
import java.util.Scanner; import java.util.*; public class Main{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("输入字符串:"); String test = input.nextLine(); //nextLine()的输入是碰到回车就终止输入,next()方法是碰到空格. TreeMap<Cha...
string str="abc123 ";int t1=0;//数字个数 int t2=0;//字母个数 int t3=0;//空格数 for(int i=0;i<str.length;i++){ if(用正则表达式来判定str.substring(i,1)的值是否为数字){ t1++;} else if(用正则表达式来判定str.substring(i,1)的值是否为字母){ t2++;} else if(用...
(): /*逐次给数组元素str[i]赋值,但不回显在屏幕上*/ printf("州'); /*以星号代替输入字符的个数*/ if(str[i]=='\x0 d') break;/*若输入回车则终止循环*/ } i=0; while(str[i]!='\xOd') printf("%c",str[i++]); /*逐次输出字符数组的各个元素*/ printf("\n"); getch(); /*...
英文辅音字母是除A、E、I、O、U以外的字母。本题要求编写程序,统计给定字符串中大写辅音字母的个数。输入格式:输入在一行中给出一个不超过80个字符、并以回车结束的字符串。
因为最后输出时有一个enter会自动计入最后的其他字符中,所以other的初值为-1.还可以用数组来存放字符串...