找零(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())
全部评论

相关推荐

CARLJOSEPH...:宝宝你戾气太大了
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务