#include <iostream>
#include <cstring>
using namespace std;
int * count (const char * const s)
{
int *count = new int [10];
for(int j = 0;j < 10;j++)
{
count[j] = 0;
for (int k = 0;k < strlen(s);k++)
{ if (s[k]-48 == j)
{
count[j]++;
}
}
}
return count;
delete [] count;
}
int main()
{
int * counts = count("0000");
for (int k = 0;k < 10;k++)
{
cout << counts[k] << " ";
}
return 0;
}
上面这段代码中包含
int * count (const char * const s)
重新设计函数,讲统计结果数组作为参数COUNTS传递给函数
void count(const char * const s,int * counts,int size)
眼眸繁星
当年话下