杭州电子科技大学 ACM 1008题 我的程序在VC上正常运行,但ACM上无法通过,帮我看看错在哪里?

题目:Thehighestbuildinginourcityhasonlyoneelevator.ArequestlistismadeupwithNpositivenum... 题目: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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.

Output
Print the total time on a single line for each test case.

Sample Input
1 2
3 2 3 1
0

Sample Output
17
41

我的程序:
#include<iostream>
using namespace std;

int up(int d,int& t){return t=t+6*d+5;};
int down(int d,int& t){return t=t+4*d+5;};

int main(){
int n;
int t=0;
int a=0;
int b=0;
cin>>n;
if(n==0)
return 0;
for(int i=0;i<n;i++){
cin>>a;
if(a==0)
return 0;
if(a>=b)
up(a-b,t);
else down(b-a,t);
b=a;
}
cout<<t<<endl;
return 0;
}
展开
 我来答
百度网友d73d192
2012-04-20
知道答主
回答量:5
采纳率:0%
帮助的人:5.9万
展开全部
先不讨论算法对不对,首先输出格式就不对,我觉得是处理一个输入,得到一个输出
while(1)
{
获取一个输入,判断是否为零
/*函数调用,然后打印结果*/
}
追问
但示例输出是输入一组数据后输出一个结果啊?
Sample Input
1 2
Sample Output
17
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式