problem 1329 TLE的快速排序 有问题无法AC 检查后再改 先发上来

来源:互联网 发布:遇见软件骗术 编辑:程序博客网 时间:2024/04/29 18:09

Description
有一组数,很多很多个数,里面有一个数出现了超过一半次,请你把它找出来。

Input
先是一个N (N<=400000),然后接下来一行N个数,多组数据输入。

Output
对每个Case,输出一行,这一行只含有一个在之前数列中出现超过一半次的数。每个case之后输出一个空行。

Sample Input

11
5 5 5 5 5 5 1 2 3 4 6


Sample Output

Case 1: 5


Source

 

 

#include<iostream>
#include<stdio.h>
using namespace std;
int quicksort(int *a,int low,int high)
   {
 int sign=a[low];
    int temp=a[low];
 while(low<high)
 {
   while(low<high && a[high]>=sign)
     high--;
   a[low]=a[high];
   while(low<high && a[low]<=sign)
    low++;
   a[high]=a[low];
 }
 a[low]=temp;
 return low;
   }
void sort(int *a,int low,int high)
{
 int p;
 if(low<high)
 {
   p=quicksort(a,low,high);
   sort(a,low,p-1);
   sort(a,p+1,high);
 }
}
int main()
{
 int n,i,c=1,num;


 while(cin>>n)
 {
  int *a=new int[n];
   for(i=0;i<n;i++)
   { 
    cin>>a[i];
   }
   sort(a,0,n-1);
   
   num=a[n/2];
   cout<<"Case "<<c<<": "<<num<<endl;
   cout<<endl;
   c++;
   delete[] a;
 }
 
 return 0;
}

原创粉丝点击