PAT 1008
1008. Elevator (20)
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
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.
Input Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:
3 2 3 1
Sample Output:
41
直接上代码
1 #include <stdio.h>
2
3 int main()
4 {
5 int N;
6 int sum;
7 int i;
8 int start_pos,end_pos;
9 while(scanf("%d",&N) != EOF){
sum = ;
start_pos = ;
for(i=;i<N;++i){
scanf("%d",&end_pos);
if(start_pos < end_pos){
sum = sum + * (end_pos - start_pos);
}
else{
sum = sum + * (start_pos - end_pos);
}
start_pos = end_pos;
}
sum = sum + * N;
printf("%d\n",sum);
}
return ;
}
PAT 1008的更多相关文章
- PAT 1008数组元素右移问题
PAT 1008数组元素右移问题 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A0A1⋯AN−1)变 ...
- PAT 1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- PAT 1008 Elevator
1008 Elevator (20 分) The highest building in our city has only one elevator. A request list is mad ...
- PAT 1008 数组元素循环右移问题 (20)(代码)
1008 数组元素循环右移问题 (20)(20 分) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A ...
- PAT——1008. 数组元素循环右移问题
一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… AN-1 A0 ...
- pat 1008 Elevator(20 分)
1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...
- PAT 1008. 数组元素循环右移问题 (20)
一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 ...
- PAT 1008 数组元素循环右移问题
https://pintia.cn/problem-sets/994805260223102976/problems/994805316250615808 一个数组A中存有N(N>0)个整 ...
- PAT 1008 Elevator 数学
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
随机推荐
- 利用icepdf将pdf文件转为图片
所需jar 包为icepdf-core.jar.icepdf-extra.jar.icepdf-pro-intl.jar.icepdf-pro.jar和icepdf-viewer.jar. 示例代码如 ...
- Xcode8安装不成功, 需要升级系统. The operation couldn't be completed. cpio read error
https://developer.apple.com/library/prerelease/content/documentation/DeveloperTools/Conceptual/Whats ...
- shell编程——if语句 if -z -n -f -eq -ne -lt
if 条件then Commandelse Commandfi 别忘了这个结尾 If语句忘了结尾fitest.sh: line 14: sy ...
- Eclipse中出现Select at least one project解决办法
今天遇到个问这个问题的,顺便帮解决了,是在导入工程的时候出现的,这是因为有同名的工程的,进入windows->show view->project explorer 这里找出来删掉再导入工 ...
- 在Oracle中更新数据时,抛出:ORA-01008: not all variables bound
在Oracle中更新数据时,抛出了一个 :ORA-01008 not all variables bound, 我的理解是不是所有的变量/参数都有边界,不懂: 后来知道了,原来是“不是所有变量/参数都 ...
- MyEclipse整合Git
1. 在OSC@China申请账号,建立项目 2. MyEclipse中选择导入项目-->Git-->Projects from Git 3. 填入Git的地址.User Name和Pas ...
- leetcode@ [127] Word Ladder (BFS / Graph)
https://leetcode.com/problems/word-ladder/ Given two words (beginWord and endWord), and a dictionary ...
- linux 配置静态IP
ip配置方法是编辑sudo nano /etc/network/interfaces 树莓派默认配置 auto lo iface lo inet loopback iface eth0 inet d ...
- openstack 在线repo
https://repos.fedorapeople.org/repos/openstack/openstack-kilo/
- ./wls1036_linux32.bin: /lib/ld-linux.so.2: bad ELF interpreter
[CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决 环境: [orangle@localhost Downloads]$ uname -m ...