Copy Code code as follows:
#include <stdio.h>
void Cottime ();
Main ()
{
Cottime ();
}
void Cottime ()
{
int c, I, Nwhite, nother, ndigit[10];
Nwhite = nother = 0;
for (i=0;i<10;i++)
{
Ndigit[i] = 0;
}
while ((c = GetChar ())!= EOF)
{
Switch (c)
{
Case ' 0 ': Case ' 1 ': Case ' 2 ': Case ' 3 ': Case ' 4 ':
Case ' 5 ': Case ' 6 ': Case ' 7 ': Case ' 8 ': Case ' 9 ':
/* A hashing idea that determines the number of occurrences of a number from a method that observes how the array element value is
Can evolve into a faster weight-loss algorithm, without first sorting after the weight, sacrificing the space performance, but improve the time performance * *
ndigit[c-' 0 '] + + 1;
Break
Case ': Case '/t ': Case '/n ':
nwhite++; Break
Default
nother++;
Break
}
}
printf ("digits =");
for (i=0;i<10;i++)
{
printf ("%d", ndigit[i]);
}
printf (", white spaces =%d, other =%d/n", Nwhite, nother);
return 0;
}