找零(c++和python(面向对象))

找零

http://www.nowcoder.com/questionTerminal/944e5ca0ea88471fbfa73061ebe95728

c++

#include<iostream>
using namespace std;
int main()
{
    int n,a = 1,b = 1,c = 1,d = 1,sum = 0;
    cin>>n;
    n = 1024 - n;
    a = (n - n % 64) / 64;
    n = n % 64;
    b = (n - n % 16) / 16;
    n = n % 16;
    c = (n - n % 4) / 4;
    d = n % 4;
    sum = a + b + c + d;
    cout<<sum;
    return 0;
}

python

class Solution :
    def __init__(self,n) :
        self.n = 1024 - n 
        self.sum = 0
    def fun(self) :         #这里的'//'表示整除
        self.sum += self.n // 64 + (self.n % 64) // 16 + ((self.n % 64) % 16) // 4 + ((self.n % 64) % 16) % 4
    def resum(self) :
        return self.sum
n = int(input())
s = Solution(n)
s.fun()
print(s.resum())
全部评论

相关推荐

秋招之BrianGriffin:你再跟他说华为工资也低(相对互联网)就可以享受私信爆炸了😋
点赞 评论 收藏
分享
02-11 17:47
已编辑
门头沟学院 Java
神哥不得了:神哥来啦~建议先在网上找一些高频的八股去背,然后再去广泛的背八股,这样的学习会更有效率一些,简历的这两个项目建议换掉,换成两个高质量的项目,这样的话获得面试的比例会更高一点,专业技能的话排版要注意一下,要加句号的话就都加,要不加就都不加,荣誉奖项的话写在教育经历里边吧,这个确实没有太多的含金量
点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务