2014-01-28 回答
#include
#include
int main()
{
while (1)
{
char words[100] = { 0 };
int counts[100][2] = { { 0, 0 } };
printf("Input string:\n");
scanf("%s", &words);
int lastIndex = 0;
for (int i = 0; i < strlen(words); i++)
{
int notFound = 1;
for (int j = 0; j < strlen(words); j++)
{
if (counts[j][0] == words[i])
{
counts[j][1]++;
notFound = 0;
}
}
if (notFound)
{
counts[lastIndex][0] = words[i];
counts[lastIndex][1] = 1;
lastIndex++;
}
}
for (int i = 0; i < 15; i++)
{
printf("-");
}
printf("\nChar\tCount\n");
for (int i = 0; i < lastIndex; i++)
{
printf("%c\t%d\n", counts[i][0], counts[i][1]);
}
printf("\nTotal: %d\n\n", strlen(words));
}
}