题解 | #找零#

找零

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

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new  Scanner(System.in);
        int N = 1024 - sc.nextInt();
        int cnt = 0;
        while(N >= 1024) {
            N -= 1024;
            cnt++;
        }
        while(N >= 64) {
            N -= 64;
            cnt++;
        }
        while(N >= 16) {
            N -= 16;
            cnt++;
        }
        while(N >= 4) {
            N -= 4;
            cnt++;
        }
        while(N >= 1) {
            N--;
            cnt++;
        }
        System.out.println(cnt);
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
秋盈丶:后续:我在宿舍群里和大学同学分享了这事儿,我好兄弟气不过把他挂到某脉上了,10w+阅读量几百条评论,直接干成精品贴子,爽
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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