本来不想写这题的,但是想想最近沉迷玩雨世界,班长又问我这题,就草草写了一下
代码如下:
#include<stdio.h>
#include<math.h>
struct parking{int distance;int remain;int speed;int time;int jud;
}parking[50];
void input(int n);int main(void)
{int n, area = 0, min_d = 1000000000;scanf("%d", &n);input(n);//处理for(int i = 0; i < n; i++){if(parking[i].speed > 0 || (parking[i].speed == 0 && parking[i].remain))parking[i].jud = 1;else if(parking[i].remain + (int)round(parking[i].speed * parking[i].time / 10.0) > 0)parking[i].jud = 1;elseparking[i].jud = 0;}//得到最小并输出for(int i = 0; i < n; i++)if(parking[i].jud && parking[i].distance < min_d)area = i + 1, min_d = parking[i].distance;printf("%d", area);return 0;
}
void input(int n)
{for(int i = 0; i < n; i++)scanf("%d", &parking[i].distance);for(int i = 0; i < n; i++)scanf("%d", &parking[i].remain);for(int i = 0; i < n; i++)scanf("%d", &parking[i].speed);for(int i = 0; i < n; i++)scanf("%d", &parking[i].time);return;
}
简单的struct结构运用,没啥好说的