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

又一个用qsort搞定的水题!

Posted by ngn999 at 2008-07-25 08:46:13 on Problem 3664
#include <stdio.h>
struct ab{
	int id;
	int first;
	int second;
}abc[50000];
int cmp1(const void *a, const void *b){
	return ((struct ab *)a)->first - ((struct ab *)b)->first;
}
int cmp2(const void *a, const void *b){
	return ((struct ab *)a)->second - ((struct ab *)b)->second;
}


int main()
{
	int n,k, i;

	scanf("%d%d", &n,&k);
	for(i = 0; i < n; i++){
		scanf("%d%d",&abc[i].first, &abc[i].second);
		abc[i].id = i +  1;
	}
	qsort((void *)abc, n,sizeof(abc[0]),cmp1);
	qsort((void *)(&abc[n - k]), k,sizeof(abc[0]),cmp2);
	printf("%d\n", abc[n-1].id);
	return 0;
}




		

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