2023-08-09力扣每日一题

链接:

1281. 整数的各位积和之差

题意:

十进制每一位的积减去每一位的和

解:

十进制位处理

实际代码:

c++ 复制代码
#include<iostream>
using namespace std;
int subtractProductAndSum(int n)
{
    int t1=1,t2=0;
    while(n)
    {
        t1*=n%10;
        t2+=n%10;
        n/=10;
    }
    //cout<<t1<<" "<<t2<<endl;
    return t1-t2;
}
int main()
{
    int n;cin>>n;
    int ans=subtractProductAndSum(n);
    cout<<ans<<endl;
}

限制:

  • 1 <= n <= 10^5
相关推荐
文丑颜不良啊5 小时前
LeetCode876~900题目解析
java·leetcode
木井巳14 小时前
【动态规划: 路径问题】不同路径
java·算法·leetcode·动态规划
晒太羊的猫15 小时前
hot100子串
java·算法·leetcode
海清河晏11116 小时前
加油站问题
数据结构·算法·leetcode
Nuanyt17 小时前
LeetCode Hot 100 · 双指针 3 题 Java
java·笔记·算法·leetcode·双指针
文丑颜不良啊19 小时前
LeetCode851~875题目解析
java·leetcode
Navigator_Z19 小时前
LeetCode //C - 1304. Find N Unique Integers Sum up to Zero
c语言·算法·leetcode
?abc!1 天前
(数组)581. 最短无序连续子数组
数据结构·算法·leetcode
hold?fish:palm1 天前
40 二叉树的直径
c++·leetcode
guo_wen_qiang1 天前
二叉树的层序遍历-使用双端队列Deque
算法·leetcode·1024程序员节