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
- PAT 1008
- PAT 1008
- pat 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- pat 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT 1008
- PAT Basic 1008
- PAT BASIC 1008
- PAT(A) 1008
- PAT Basic 1008
- 1000个苹果分成10堆
- onActivityResult无法回调的问题
- 3、算术运算符的使用(0106)
- 递归、递推(斐波那契数列)
- MySQL 查看编码 排序规则
- pat 1008
- 【网站高性能 6】----大型网站架构演化知多少(一)
- Invert Binary Tree
- CoordinatorLayout使用详解
- mysql浮点数decimal、float、double默认进位方式
- 读书笔记第一章第五节 1.5连接MySQL
- 【JQuery】实例--单击文本,文本消失
- 4、计算键盘输入会员卡号之和
- Golang中结构体转byte数组