ZZULIOJ-1153: 简易版最长序列
作者:互联网
#include<stdio.h>
#include<string.h>
#include<math.h>
void K(int a[],int n)
{
int num;
for (int i = 0; i <= n - 1; i++)
{
for (int r = i + 1; r <= n - 1; r++)
{
if (a[i] > a[r])
{
num = a[i];
a[i] = a[r];
a[r] = num;
}
}
}
}
int main()
{
int n, a[10000], m, b, c;
scanf("%d", &m);
for (int r = 1; r <= m; r++)
{
memset(a, 0, sizeof(a));
b = 1;
c = 1;
scanf("%d", &n);
for (int i = 0; i <= n - 1; i++)
scanf("%d", &a[i]);
K(a, n);/*排序后相同项会彼此相连*/
for (int e = 0; e <= n - 2; e++)
{
while (a[e] == a[e + 1])
{
b++;
e++;
}
if (b >= c)
{
c = b;/*计算最长相同项长度并记录*/
}
b = 1;
}
printf("%d\n", c);
}
return 0;
}
标签:main,10000,int,ZZULIOJ,1153,简易版,num,include,最长 来源: https://blog.csdn.net/qq_61410013/article/details/122125462