Microsoft的考验――查找第二大的数

#include<stdio.h> 
int main()
{
    int n,m,t,max,max1;
    scanf("%d",&n);
    while(n--)
    {
        max=-100000;
        max1=-100000;
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d",&t);
            if(t==max || t==max1) continue;
            if(t>max)
            {
                max1=max;
                max=t;
            }
            else
            {
                if(t>max1)
                {
                    max1=t;
                }
            }
        }
        if(max1!=-100000 && max!=max1) 
        printf("%d\n",max1);
        else 
        printf("None\n");
    }
}

猜你喜欢

转载自www.cnblogs.com/zzjam--1/p/11447019.html