输入十个数,求出不同相同数的个数,及其个数的多少
#include <iostream.h>
const int N = 10;
void main()
{
struct
{
int num;
int tim;
}R[N];
int i;
int ar[N];
cout << "please input ten numbers : ";
for(i=0; i<N; i++)
cin >> ar[i];
R[0].num = ar[0];
R[0].tim = 1;
int j;
int t = 0;
int m;
for(i=1; i<N; i++)
{
for(j=0; j<=t; j++)
if(R[j].num = ar[i])
R[j].tim ++;
else //错误
{
t ++;
R[t].num = ar[i];
R[t].tim = 1;
m = t;
}
}
for(i=0; i<m; i++)
cout << R[i].num << " " << R[i].tim << endl;
}
这个题目的t是错误的,请指出如何在运行完if后结束
[此贴子已经被作者于2006-9-21 20:22:21编辑过]