题解:AtCoder AT_awc0005_a Reward of Multiples
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderA - Reward of Multiples【题目描述】Takahashi is in charge of accounting at his company and is managing this month’s bonus payments to employees.高桥负责公司的会计工作正在管理本月给员工的奖金发放。The company hasN NNemployees, and each employee has a compensation amount determined by their performance. The compensation amount for thei ii-th employee isP i P_iPiyen.公司有N NN名员工每位员工的奖金金额根据其绩效确定。第i ii名员工的奖金金额为P i P_iPi日元。The company president gave the following instruction: “I would like to give a special allowance to employees whose compensation amount is a multiple ofK KK. First, please tell me the total of the compensation amounts for the applicable employees.”公司总裁给出了以下指示“我希望向奖金金额是K KK的倍数的员工发放特殊津贴。首先请告诉我符合条件员工的奖金金额总和。”Help Takahashi find the total of the compensation amounts for employees whose compensation amount is a multiple ofK KK(that is,P i P_iPiis divisible byK KK). If there are no such employees, the total is0 00.帮助高桥计算奖金金额是K KK的倍数即P i P_iPi能被K KK整除的员工奖金金额总和。如果不存在这样的员工总和为0 00。【输入】N NNK KKP 1 P_1P1P 2 P_2P2… \ldots…P N P_NPNThe first line contains an integerN NNrepresenting the number of employees and an integerK KKused for the divisibility check, separated by a space.The second line containsN NNintegersP 1 , P 2 , … , P N P_1, P_2, \ldots, P_NP1,P2,…,PNrepresenting the compensation amounts of each employee, separated by spaces.【输出】Print the total of the compensation amounts for employees whose compensation amount is a multiple ofK KK, on a single line.【输入样例】5 3 6 7 9 12 5【输出样例】27【解题思路】【算法标签】#模拟#【代码详解】#includebits/stdc.husingnamespacestd;#defineintlonglongintn,k,ans;// n: 数据个数k: 除数ans: 总和signedmain(){cinnk;// 读入数据个数和除数for(inti1;in;i){intx;cinx;// 读入当前数字if(x%k0)// 如果当前数字能被k整除{ansx;// 累加到总和中}}coutansendl;// 输出总和return0;}【运行结果】5 3 6 7 9 12 5 28
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2567449.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!