pat 1008

来源:互联网 发布:大连seo服务公司 编辑:程序博客网 时间:2024/05/17 12:20

1.题目

https://www.patest.cn/contests/pat-a-practise/1008

2.题意分析及坑点

(1).我们需要注意的是题目中的这么一句话:

“For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.”

翻译后的话为:对于给定的一个序列,你需要计算到达列表中每一个楼层的总时间,电梯是 从第0层开始,且最后不必回到第一楼。

3.代码

#include <stdio.h>#define size 1001/*1.最后不必回到第0层或者第1层,注意题目要求 */ int main(){int number;int array[size], dealWithArray[size]={0};//一开始的数组和处理后的数组 scanf("%d",&number);int i ;array[0] = 0;//the start is zero floor for(i = 1;i <= number;i++){scanf("%d",&array[i]);dealWithArray[i-1] = array[i] - array[i-1];//求出两个楼层之间的距离 }int sum = 0 ;//初始化sum的值为0sum = number * 5;//加上所有楼层停的时间 for(i = 0; i<number ;i++){//printf("%d\n",dealWithArray[i]);if(dealWithArray[i] < 0){sum = sum + ((-1) * dealWithArray[i] * 4) ;}else if(dealWithArray[i]>0)sum = sum +( dealWithArray[i] * 6 );} printf("%d",sum);}/**3 2 3 11 0**/


0 0
原创粉丝点击