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有问题,改成sort就ac了

Posted by zhucheng at 2005-07-20 19:54:24 on Problem 2497
In Reply To:证明我明白了,但是帮我看一下那里错了,谢谢了 Posted by:sunmoonstar_love at 2005-07-20 19:45:09
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
int cmp1(int* a, int* b)
{
    if(*a<*b)
        return 1;
    return 0;
}
int cmp2(int* a, int* b)
{
    if(*a>*b)
        return 1;
    return 0;
}
    
int bill[25],steve[25],linus[25],s1,s2,s3,i,j,k,test,sce,minute,problem,score1,score2,score3;
int main()
{
    scanf("%d",&test);
    for(sce=1; sce<=test; sce++)
    {
        scanf("%d%d",&minute,&problem);
        for(i=0; i<problem; i++)
        {
            scanf("%d",&bill[i]);
            steve[i] = linus[i] = bill[i];
        }    
       // qsort(steve,problem,sizeof(int),(int(*)(const void*, const void*))cmp2);
		sort(steve,steve+problem);
        for(i=1; i<problem; i++)
        {
            steve[i] += steve[i-1];
            linus[i] += linus[i-1];
            bill[i] += bill[i-1];
        }
        s1 = s2 = s3 = score1 = score2 = score3 = 0;
        for(i=0; i<problem; i++)
        {
            if(steve[i]<=minute)
            {
                score2 += steve[i];
                s2++;
            }  
            else 
                break;
        }
        printf("Scenario #%d:\nSteve wins with %d solved problems and a score of %d.\n\n",sce,s2,score2);
            
    }
    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