# 【简单题】泥塑课

2 篇文章 0 订阅

3
10 10 2 Jill
5 3 10 Will
5 5 10 Bill
4
2 4 10 Cam
4 3 7 Sam
8 11 1 Graham
6 2 7 Pam
-1

Bill took clay from Will.
Graham took clay from Cam.

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
struct student
{
char* name;
int _long;
int wide;
int hight;
};
int stu_num[80];
int pos = 0;
student inf[80];
cin >> stu_num[0];
int k = 0; //输入完成后就是总的班级数
for (; stu_num[k] != -1; k++)
{
for (int i = 0; i<stu_num[k]; i++)
{
cin >> inf[pos]._long >> inf[pos].wide >> inf[pos].hight;
inf[pos].name = new char[80];
cin.getline(inf[pos].name, 10);
inf[pos].name = inf[pos].name + 1;
pos++;
}
cin >> stu_num[k + 1];
}
int max, min;
char* max_stu_name, *min_stu_name;
pos = 0;
for (int i = 0; stu_num[i] != -1; i++)
{
for (int j = 0; j<stu_num[i]; j++)
{
if (j == 0)
{
max = inf[pos]._long*inf[pos].wide*inf[pos].hight;
min = inf[pos]._long*inf[pos].wide*inf[pos].hight;
max_stu_name = inf[pos].name;
min_stu_name = inf[pos].name;
pos++;
}
else
{
if (inf[pos]._long*inf[pos].wide*inf[pos].hight>max)
{
max = inf[pos]._long*inf[pos].wide*inf[pos].hight;
max_stu_name = inf[pos].name;
pos++;
}
else if (inf[pos]._long*inf[pos].wide*inf[pos].hight < min)
{
min = inf[pos]._long*inf[pos].wide*inf[pos].hight;
min_stu_name = inf[pos].name;
pos++;
}
else pos++; //卡在了这里,在既不大于也不小于的情况下不作操作,但标记指针要后移
}
}
if (!strcmp(max_stu_name, min_stu_name));
else
{
if (stu_num[i] > 0)
{
cout << max_stu_name << " took clay from " << min_stu_name << ".";
if (i != k - 1) cout << endl;
}
}
}
return 0;
}

1.struct结构体中应添加一int类型变量，标记体积。

2.如果想按照班级分开，可以将链表与顺序表结合起来，这样班级号就作为索引，一个班级号指向一个struct结构体数组的首地址。

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
08-02 134
04-04 1939
08-06 418
12-12 202
04-17 933
11-16 770
02-12 550
08-22 544
10-24 863
12-31 102

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。