标签:-- mic img image mamicode tmp scanf 柱状图 include
#include<stdio.h>
#include<stdlib.h>
int main()
{
char c;
int a[3]={0};
char *p[3]={"alp","num","oth"};
int temp;
char *ptmp;
int i,j;
while(scanf("%c",&c)!=EOF)
{
if(c>=‘a‘&&c<=‘z‘ || c>=‘A‘&&c<=‘Z‘)
{
a[0]++;
}else if(c>=‘1‘&&c<=‘9‘)
{
a[1]++;
}else {
a[2]++;
if(c==‘\n‘)
{
break;
}
}
}
for(i=3;i>1;i--)
{
for(j=0;j<i-1;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;//交换整型数组
ptmp=p[j];
p[j]=p[j+1];
p[j+1]=ptmp;//交换字符数组指针中的指针
}
}
}
printf("a[0]=%d a[1]=%d a[2]=%d\n",a[0],a[1],a[2]);
printf("p[0]=%s p[1]=%s p[2]=%s\n",p[0],p[1],p[2]);
for(i=0;i<a[0];i++)
{
if(0==i)
{
printf("%3d ",a[0]);
}else printf("***** ");
if(a[0]-a[1]==i)
{
printf("%3d ",a[1]);
}else if(i>a[0]-a[1])
{
printf("***** ");
}
if(a[0]-a[2]==i)
{
printf("%3d ",a[2]);
}else if(i>a[0]-a[2])
{
printf("***** ");
}
printf("\n");
}
printf("%4s %4s %4s\n",p[0],p[1],p[2]);
return 0;
}
标签:-- mic img image mamicode tmp scanf 柱状图 include
原文地址:https://www.cnblogs.com/buxiu888/p/14093271.html