|
*停權中*
|
挨 教他釣魚就好
何必連魚都給他
引用:
Originally posted by harrisonlin
#include <stdlib.h>
#include <iostream.h>
void main()
{
const int DigitCount = 6;
char input[80];
int result[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
cin >> input;
for(int index = 0; index < DigitCount; index++)
{
switch(input[index])
{
case '0':
result[0]++;
break;
case '1':
result[1]++;
break;
case '2':
result[2]++;
break;
case '3':
result[3]++;
break;
case '4':
result[4]++;
break;
case '5':
result[5]++;
break;
case '6':
result[6]++;
break;
case '7':
result[7]++;
break;
case '8':
result[8]++;
break;
case '9':
result[9]++;
break;
}
}
for(index = 0; index < 10; index++)
{
cout << "char '" << index << "' appears " << result[index] << " times." << endl;
}
}
|
|