7-61 懒虫小鑫
代码:
正确代码:#include <stdio.h>
#include <stdlib.h>
struct node
{
int x;
int y;
}a[100100];
int sum;
int cmp(struct node* a,struct node* b)
{
if(a->x==b->x)
{
return (*a).y<(*b).y?1:0;
}
else
{
return (*a).x>(*b).x?1:0;
}
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
qsort(a,n,sizeof(struct node),cmp);
int sum=0;
for(int i=0;i<m;i++)
{
sum+=a[i].y;
}
printf("%d",sum);
return 0;
}
7-62 队的基本操作
代码:
#include<iostream>
using namespace std;
#define ERROR 0
#define OK 1
#define MAXQSIZE 10
typedef int QElemType;
typedef int Status;
typedef struct{
QElemType *base;
int rear;
int front;
}SqQueue;
Status