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

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值