C++Harry呀 2024-02-02 20:47 采纳率: 61.5%
浏览 0
已结题

please help me with c++

img

img

img


please help me with c++
please help me with c++
please help me with c++please help me with c++
please help me with c++please help me with c++
please help me with c++
my code

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N],x,n;
int main(){
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        cin>>x;
        if(a[i]-x<=0)b[i]=a[i]-x;
        else c[i]=x-a[i];
        
    }
    int ans=0;
    for(int i=1; i <= n; i++){
        if(b[i]>b[i-1]) ans+=b[i]-b[i-1];
    }
    for(int i=1; i <= n; i++){
        if(c[i]>c[i-1]) ans+=c[i]-c[i-1];
    }    
    printf("%d",ans);
    
        return 0;
        
        
}


  • 写回答

2条回答 默认 最新

  • 龙傲天☆ 2024-02-02 20:54
    关注

    I题:

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e5 + 10;
    int a[N], b[N], c[N], x;
    int main() {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &x);
            if (a[i] - x >= 0) b[i] = a[i] - x;
            else c[i] = x - a[i];
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (b[i] > b[i - 1]) ans += b[i] - b[i - 1];
        }
        for (int i = 1; i <= n; i++) {
            if (c[i] > c[i - 1]) ans += c[i] - c[i - 1];
        }
        cout << ans;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月23日
  • 已采纳回答 2月15日
  • 修改了问题 2月2日
  • 请提交代码 2月2日
  • 展开全部

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表