嗯!如此统计文章字符类型和个数

来源:互联网 发布:怎样合理网络理财 编辑:程序博客网 时间:2024/04/30 06:08

#include <iostream>
using namespace std;
int main()
{int i,j=0,A=0,b=0,data=0,other=0,space=0;
 char a[3][80];
 for(i=0;i<3;i++)
 {  cin>>a[i];
    for(j=0;j<80,a[i][j]!='\0';j++)
  {if(a[i][j]>='A'&&a[i][j]<='Z')
    A++;
       else  if(a[i][j]>='a'&&a[i][j]<='z')
     b++;
        else  if(a[i][j]>='0'&&a[i][j]<='9')
      data++;
         else  if(a[i][j]=='')
       space++;
        else
         other++;
  }
 }
 cout<<"big char:"<<A<<endl;
 cout<<"little char:"<<b<<endl;
 cout<<"data:"<<data<<endl;
 cout<<"space:"<<space<<endl;
 cout<<"others:"<<other<<endl;
 return 0;
}

 


#include <iostream>
using namespace std;
int main()
{int i,j=0,A=0,b=0,data=0,other=0,space=0;
 char a[3][80];
 for(i=0;i<3;i++)
 { gets(a[i]);                             //gets与cin有所不同
    for(j=0;j<80,a[i][j]!='\0';j++)
  {if(a[i][j]>='A'&&a[i][j]<='Z')
    A++;
       else  if(a[i][j]>='a'&&a[i][j]<='z')
     b++;
        else  if(a[i][j]>='0'&&a[i][j]<='9')
      data++;
         else  if(a[i][j]==' ')
       space++;
        else
         other++;
  }
 }
 cout<<"big char:"<<A<<endl;
 cout<<"little char:"<<b<<endl;
 cout<<"data:"<<data<<endl;
 cout<<"space:"<<space<<endl;
 cout<<"others:"<<other<<endl;
 return 0;

原创粉丝点击