Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:那位牛人,用qsort()搞定,进来帮我看下哈!搞不明白哪有错啊?

Posted by smark at 2007-04-08 23:59:27 on Problem 2623
In Reply To:那位牛人,用qsort()搞定,进来帮我看下哈!搞不明白哪有错啊? Posted by:woshiniya at 2007-03-18 22:08:13
> #include <iostream>
> #include <iomanip>
> #include <algorithm>
> using namespace std;
> int cmp(const void *a, const void *b) {   	
> if(*(unsigned int*)a>*(unsigned int*)b)
> 		return 1;
> 	else if(*(unsigned int*)a==*(unsigned int*)b) //还是看别人的后,加的,原因不明
> 
> 		return 0;
> 	return -1;
> 
> }
> 
> void main() {
> 	int size, i;
> 	unsigned int *nm;
> 	float ans;
> 	scanf("%d", &size);
> 	nm = new unsigned int[size];
> 	for(i = 0; i < size; i++)
> 		scanf("%d", &nm[i]);
> 	qsort(nm, size, sizeof(nm), cmp);
> 	if(size % 2 == 0)
> 		ans = (nm[size/2-1] + nm[size/2]) / 2.0;
> 	else
> 		ans = nm[(size-1)/2];	
> 	printf("%.1f\n", ans);
> 	delete[]nm;
> }
> 	
> 
> unsigned int 装不下2^32-1吧,试试用unsigned long看看....   by  新手

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator