poj 2070 Filling Out the Team
這道題也什麼好寫的,需要注意的地方就是輸入的時候,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;
}
最後更新:2017-04-03 05:39:40