【乱搞】【AOJ-149】简易版最长序列

Description
给你一组数(未排序),请你写设计一个程序:求出里面个数最多的数。并输出这个数的长度。
例如:给你的数是:1、 2、 3、 3、 4、 4、 5、 5、 5 、6, 其中只有6组数:1, 2, 3-3, 4-4, 5-5-5 and 6.
最长的是5那组,长度为3。所以输出3。

Input
第一行为整数t((1 ≤ t ≤ 10)),表示有n组测试数据。
每组测试数据包括两行,第一行位数组的长度n (1 ≤ n ≤ 10000)。第二行为n个整数,所有整数Mi的范围都是(1 ≤ Mi ≤ 2^32)

Output
对应每组数据,输出个数最多的数的长度。

Sample Input
1
10
1 2 3 3 4 4 5 5 5 6

 
Sample Output
3
思路:
1、先对数组进行排序
2、排序后对数组中不同数字的个数进行统计
3、求出数字个数的最大值
 
参考代码:
#include<stdio.h>
#include<stdlib.h>
#define LEN 10000+10
void sort(int *a,int n);//冒泡排序

int main()
{
    int a[LEN],b[LEN]={0};
    int t,n,k=0,i,j,temp;
    scanf("%d",&t);
    
    while(t--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=1;
        }
        
        sort(a,n);//对数组进行排序
        
        for(k=0,j=1;j<n;j++)//统计字数个数
        {
            if(a[j]==a[j-1]) 
                b[k]++;
            else 
                k++;
        }

        temp=b[0];

        for(i=0;b[i];i++)//找出字数最大值
        {
            if(temp<b[i])
                temp=b[i];
        }
        printf("%d
",temp);

        k=0;
    }
    //system("PAUSE");
    return 0;
}                  

void sort(int *a,int n)
{
    int i,j;
    int temp;
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
}
 
原文地址:https://www.cnblogs.com/ahu-shu/p/3467063.html