【算法笔记】1016 部分A+B、1026 程序运行时间

【算法笔记】1016 部分A+B、

1016 部分A+B

题目:

给定一个数字66178 以及关键数字 6,在66178里面有两个6,则pa = 66

在这里插入图片描述

代码:

#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{

    long long a, b;
    int a1, b1;
    int sum = 0;
    int pa = 0;
    int pb = 0;
    cin >> a >> a1 >> b >> b1; // 3862767 6 13530293 3
    int i = 0;
    while (a != 0)
    {

        if (a % 10 == a1)
            pa = pa * 10 + a1;
            a = a / 10;
    }

    while (b != 0)
    {
        if (b % 10 == b1)
            pb = pb * 10 + b1;
            b = b / 10;
    }
    
    sum = pa + pb;
    
    cout << sum << endl;

    return 0;
}

重点:

对每一个数字里面的值一个一个进行判定

while (a != 0)//当这个数字不等于0的时候
    {

        if (a % 10 == a1)//取出数字的每一位进行比较
            //按照题目要求进行操作
            a = a / 10;//每一次都必须除以10,更新这个数字
    }

1026 程序运行时间

题目:

在这里插入图片描述

代码:

#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b; // 123 4577973

    int ans = 0;
    ans = b - a;
    if (ans % 100 >= 50)
    {
        ans = ans / 100 + 1;
    }
    else
    {
        ans = ans / 100;
    }

    printf("%02d:%02d:%02d\n", ans / 3600, ans / 60 % 60, ans % 60);

    return 0;
}

重点:

ans / 3600//时
ans / 60 % 60//分
ans % 60//秒
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值