当前位置: 代码迷 >> 综合 >> poj 2070 Filling Out the Team
  详细解决方案

poj 2070 Filling Out the Team

热度:74   发布时间:2024-01-11 16:46:13.0

这道题也什么好写的,需要注意的地方就是输入的时候,speed是double型的,如果用 scanf 输入就很是麻烦,

因为对于后面的判断 if (sp==0 && w==0 && st==0) ,用 scanf 输入不好操作。。。

另外的一点就是这道题就应该用结构体来做,思路一目了然,我知道直接用数组来写代码量会少很多,但是还是选择了结构体,

这个题目卫星数据很多,不用结构体感觉结构体就无用武之地了。。。


接下来看题目:

题意:给出了球场上Wide Receiver,Lineman,Quarterback三个位置所需人员的最低属性(speed,weight strength)要求,输入:三个数据,为别为speed、weight 、strength,若输入的速度低于或等于球场上位置的要求,体重和力量大于或等于球场上位置的要求,则输出相应的符合位置,若有多个符合的位置,中间用一个空格隔开输出,如没有符合位置,则输出

No positions

思路:将输入属性与球场位置的要求属性依次比较即可。

一直纳闷,为什么要速度低于speed limit,不是速度越快越好吗。。。

AC的代码:

#include <stdio.h>
#include <string.h>
#include <iostream>using namespace std;typedef struct s
{char * pos;double speed;int weight;int strength;
}Player;int main()
{Player player[3];player[0].pos = "Wide Receiver", player[0].speed = 4.5, player[0].weight = 150, player[0].strength = 200;player[1].pos = "Lineman", player[1].speed = 6.0, player[1].weight = 300, player[1].strength = 500;player[2].pos = "Quarterback", player[2].speed = 5.0, player[2].weight = 200, player[2].strength = 300;double sp;int w,st;int i;int flag;while(cin>>sp>>w>>st){if (sp==0 && w==0 && st==0)break;flag=0;for(i=0;i<3;i++){if (sp<=player[i].speed && w>=player[i].weight && st>=player[i].strength){flag=1;printf("%s ",player[i].pos);}}if (flag==0)printf("No positions");printf("\n");}return 0;
}




  相关解决方案