讨论 / c++ 谁帮我看看
zjys 2011-09-17 22:30:00
点我顶贴 收藏 删除
#include<iostream>

using namespace std;

int a[35];

void sort(int l,int r)

{

int i,j,x,t;

i=l;j=r;x=a[(i+j)/2];

while (i<=j)

{

while (a[i]>x) i++;

while (a[j]<x) j--;

if (i<=j)

{

t=a[i];a[i]=a[j];a[j]=t;

i++;j--;

}

if (l<j) sort(l,j);

if (i<r) sort(i,r);

}

}

int main()

{

int v,n,i;

cin>>v>>n;

for(i=0;i<n;i++)

cin>>a[i];

sort(0,n-1);

for(i=0;i<n;i++)

while (v-a[i]>=0) v-=a[i];

cout<<v<<endl;

system("pause");

return 0;

}

#1 zjys@2011-09-17 22:30:00
回复 删除
a
查看更多回复
提交回复