Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_PLAYERS 30
- #define BUDGET 300
- typedef struct {
- int price;
- double pts;
- } player_t;
- int get_players(player_t *p);
- int main(int argc, char *argv[]) {
- player_t pg[MAX_PLAYERS], sg[MAX_PLAYERS], sf[MAX_PLAYERS],
- pf[MAX_PLAYERS], ce[MAX_PLAYERS];
- int pgnum, sgnum, sfnum, pfnum, cenum, t[5], cost;
- int a, b, c, d, e;
- double currentsum, sum=0;
- printf("Enter point guards:\n");
- pgnum = get_players(pg);
- printf("Enter shooting guards:\n");
- sgnum = get_players(sg);
- printf("Enter small forwards:\n");
- sfnum = get_players(sf);
- printf("Enter power forwards:\n");
- pfnum = get_players(pf);
- printf("Enter centers:\n");
- cenum = get_players(ce);
- for (a = pgnum - 1; a>=0; a--) {
- for (b = sgnum - 1; b>=0; b--) {
- for (c = sfnum - 1; c>=0; c--) {
- for (d = pfnum - 1; d>=0; d--) {
- for (e = cenum - 1; e>=0; e--) {
- cost = pg[a].price+sg[b].price+sf[c].price+pf[d].price+
- ce[e].price;
- if (cost > BUDGET) {
- break;
- }
- currentsum = pg[a].pts+sg[b].pts+sf[c].pts+pf[d].pts+
- ce[e].pts;
- if (currentsum >= sum) {
- if (currentsum == sum) {
- printf("%.1f:", sum);
- printf("%d %.1f ", pg[a].price, pg[a].pts);
- printf("%d %.1f ", sg[b].price, sg[b].pts);
- printf("%d %.1f ", sf[c].price, sf[c].pts);
- printf("%d %.1f ", pf[d].price, pf[d].pts);
- printf("%d %.1f\n", ce[e].price, ce[e].pts);
- }
- sum = currentsum;
- t[0] = a;
- t[1] = b;
- t[2] = c;
- t[3] = d;
- t[4] = e;
- }
- }
- if (e == 0) {
- break;
- }
- }
- if (d == 0 && e == 0) {
- break;
- }
- }
- if (c == 0 && d == 0 && e == 0) {
- break;
- }
- }
- if (b == 0 && c == 0 && d == 0 && e == 0) {
- break;
- }
- }
- printf("Point guard: %3d\t%.1f\n", pg[t[0]].price, pg[t[0]].pts);
- printf("Shooting guard: %3d\t%.1f\n", sg[t[1]].price, sg[t[1]].pts);
- printf("Small forward: %3d\t%.1f\n", sf[t[2]].price, sf[t[2]].pts);
- printf("Power forward: %3d\t%.1f\n", pf[t[3]].price, pf[t[3]].pts);
- printf("Center: %3d\t%.1f\n", ce[t[4]].price, ce[t[4]].pts);
- cost = pg[t[0]].price + sg[t[1]].price + sf[t[2]].price + pf[t[3]].price +
- ce[t[4]].price;
- printf("Points: %.1f\tCost: %d\n", sum, cost);
- return 0;
- }
- int get_players(player_t *p) {
- int n=0, priceP;
- double ptsP;
- while (scanf("%d %lf", &priceP, &ptsP) == 2) {
- if (n>MAX_PLAYERS) {
- printf("More than %d players entered.\nExit failure.\n",
- MAX_PLAYERS);
- exit(EXIT_FAILURE);
- }
- if (priceP==0||ptsP<1e-5) {
- return n;
- }
- p[n].price = priceP;
- p[n].pts = ptsP;
- n++;
- }
- return n;
- }
Add Comment
Please, Sign In to add comment