16,551
社区成员
发帖
与我相关
我的任务
分享#define MAX_NUM 100 // 数组中容许的最大值
void StatNumber(int *p, int n)
{
int count = 0,
array[MAX_NUM][2];
memset(array, 0xff, sizeof(array));
for(int i = 0; i < n; ++i)
{
if( array[p[i] - 1][0] == -1 )
{
count++;
array[p[i] - 1][0] = 1;
}
else
{
array[p[i] - 1][1] = i;
}
}
cout << "Total numbers: " << count << endl;
for(int j = 0; j < MAX_NUM; ++j)
{
if( array[j][1] != -1 )
{
cout << "The last postion of " j + 1 << " is " << array[j][1] << endl;
}
}
}