请用C++编写一个算法,完成以下功能:

来源:百度知道 编辑:UC知道 时间:2024/05/09 08:59:20
从键盘输入一段文字,以$作结束符号;
统计文字中的文本行数,字母,数字以及其他符号的数量,并在屏幕上显示;

#include<iostream.h>

void main()
{
char a;
int nChar,nNum,nRow,nOth;
nChar=nNum=nRow=nOth=0;
a=cin.get();
while(a!='$')
{
if((a<='Z'&&a>='A')||(a<='z'&&a>='a'))
nChar++;
else if(a<='9'&&a>='0')
nNum++;
else if(a==0x0A)
nRow++;
else
nOth++;
a=cin.get();
}
cout<<"行数:"<<nRow<<endl;
cout<<"字母:"<<nChar<<endl;
cout<<"数字:"<<nNum<<endl;
cout<<"其他:"<<nOth<<endl;
}

/*********************
**File:
**Use: Statistic characters and their counts
**Author: Bureau
**Create Time: Nov 13th, 2007
**Last Edit:
*********************/

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>