我想通过声明一个指针int*p;来指向结构stu[0].deadline,并通过p+1,p+2,的形式f分别指向stu[0].deadline,stu[1].deadline,stu[2].deadline.
不知道应该怎么声明和使用这个指针,是hotel*p还是int*p,如果是hotel*p的话应该怎么达到该效果。
代码如下:(传上去格式就没了,而且容易丢东西,麻烦看看照片)
// 房间安排.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
int maopao(int*p,int n);
int _tmain(int argc, _TCHAR* argv[])
{
int s=0;
int n=0;
int i=0;
struct hotel
{
int room;
int date;
int during;
int deadline;
};
hotel stu[10000];
printf("请输入测试数据组数:\n");
scanf("%d",&n);
printf("请输入每组的订单数:\n");
scanf("%d",&s);
while(n--)
{
for(i=0;i
{
scanf("%d",&stu[i].room);
scanf("%d",&stu[i].date);
scanf("%d",&stu[i].during);
stu[i].deadline=stu[i].date+stu[i].during;
}
for(int y=0;y
{
for(int u=0;u
{
if(stu[u].date>stu[u+1].date)
{
hotel temp=stu[u];
stu[u]=stu[u+1];
stu[u+1]=temp;
}
}
}
int*p;
p=; //此处已经将结构按起始日期从大到小进行排序了4 9 6 3 10 4 3,12,6
int re=maopao(p,s);
int w=0;
int total;
while(w
{
if(stu[w].date
total=total+stu[w].room;
if(stu[w].date>=re&&total>stu[w].room)
total=total+0;
if(stu[w].date>=re&&total<stu[w].room)
total=stu[w].room;
w++;
}
printf("%d\n",total);
}
return 0;
}
int maopao(int*p,int n)
{
for(int i=0;i
for(int q=0;q
{
if(*(p+q)>(p+q+1))
{
int num=(p+q);
(p+q)=(p+q+1);
*(p+q+1)=num;
}
}
return *(p+0);
}