1413 权势二进制
题目来源: CodeForces
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注
一个十进制整数被叫做权势二进制,当他的十进制表示的时候只由0或1组成。例如0,1,101,110011都是权势二进制而2,12,900不是。

当给定一个n的时候,计算一下最少要多少个权势二进制相加才能得到n。


Input
单组测试数据。
第一行给出一个整数n (1<=n<=1,000,000)

Output
输出答案占一行。


Input示例
9
Output示例
9

打表可以找出规律,发现要求的答案就是当前这个数每一位的最大值。

#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main()
{
    LL n;
    cin>>n;
    LL maxIndex=-1;
    while(n)
    {
       LL tmp=n%10;
       maxIndex=max(maxIndex,tmp);
       n/=10;
    }
    cout<<maxIndex<<endl;
    return 0;

}

相关文章:

  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-10-19
  • 2021-11-01
猜你喜欢
  • 2021-04-07
  • 2022-12-23
  • 2021-05-17
  • 2021-07-30
  • 2022-12-23
  • 2021-11-04
  • 2021-06-08
相关资源
相似解决方案