PAT (Advanced Level) 1008. Elevator (20)

简单模拟。

注意a[i]==a[i-1]的情况。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std; const int maxn=+;
int n,a[maxn]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
a[]=;
int ans=;
for(int i=;i<=n;i++)
{
if(a[i]>a[i-]) ans=ans+(a[i]-a[i-])*,ans=ans+;
else if(a[i]<a[i-]) ans=ans+(a[i-]-a[i])*,ans=ans+;
else ans=ans+;
}
printf("%d\n",ans);
return ;
}
上一篇:jenkins登录后页面显示为空的问题


下一篇:PAT (Advanced Level) 1035. Password (20)