人人车笔试

人人车的笔试题,有不懂的留言,我修改
 第一题:人民币分为(1,5,10,20,50,100)的金额,若交易金额为19,收银(50),找零(20+10+1)交易所需人民币张数为4.或者收银(10+5+1+1+1+1)交易所需人民币张数为6.输入交易金额n,输出交易所需最少人民币数量
 第二题:输入一个数,判断其是否为快乐的数(各位数的平方和最后得1),陷入死循环则不是快乐的数
例如:输入:19
1^2+9^2=82;(9^2是9的平方)
8^2+2^2=68;
6^2+8^2=100;
1^2+0^2+0^2=1;
则19为快乐的数 
 第三题:求字符串数组的前缀公共子串
{“abcdef",
"abcsfds",
"abctyu"}
则结果为“abc”

{“abcdef",
"dbcsfds",
"sbctyu"}
则结果为“”(为空) 
 
全部评论
/** * 题目描述: * 第一题:人民币分为(1,5,10,20,50,100)的金额,若交易金额为19,收银(50),找零(20+10+1)交易所需人民币张数为4. * 或者收银(10+5+1+1+1+1)交易所需人民币张数为6.输入交易金额n,输出交易所需最少人民币数量 * @author young * */ public class MoneyNumberLeast { private static int[] moneyArrays = {100, 50, 20, 10, 5, 1}; private static int[] moneyNumber = new int[100]; static { //初始化获得1-99交易额的最少人民币数量 for(int i = 1; i < 100; i ++) { moneyNumber[i] = getMinNumberOfMoney(i); } } /** * n元进行分解,最少需要的人民币的数量 * @param n * @return */ public static int getMoneyNumber(int n) { int sum = 0; for(int i = 0; i < moneyArrays.length; i ++) { int number = n / moneyArrays[i]; sum += number; n = n % moneyArrays[i]; } return sum; } /** * 输入金额为n,返回最少的人民币数量 * @param n在1-99之间 * @return */ public static int getMinNumberOfMoney(int n) { if(n < 1 || n > 99) return -1; //第一种情况:直接支付不找零 int sum1 = getMoneyNumber(n); //第二种情况,支付,找零 int i = moneyArrays.length - 1; while(n / moneyArrays[i] != 0) { i--; } int sum2 = getMoneyNumber(moneyArrays[i] - n) + 1; return Math.min(sum1, sum2); } public static int getMinNumber(int n) { //100以内的人民币数量 int numberother = 0; //100元的人民币数量 int number100 = n / 100; n = n % 100; if(n > 0) { numberother = moneyNumber[n]; } return number100 + numberother; } }
点赞
送花
回复 分享
发布于 2016-07-08 11:20
1元--->1 张 2元--->2 张 3元--->3 张 4元--->2 张 5元--->1 张 6元--->2 张 7元--->3 张 8元--->3 张 9元--->2 张 10元--->1 张 11元--->2 张 12元--->3 张 13元--->4 张 14元--->3 张 15元--->2 张 16元--->3 张 17元--->4 张 18元--->3 张 19元--->2 张 20元--->1 张 21元--->2 张 22元--->3 张 23元--->4 张 24元--->4 张 25元--->2 张 26元--->3 张 27元--->4 张 28元--->4 张 29元--->3 张 30元--->2 张 31元--->3 张 32元--->4 张 33元--->5 张 34元--->4 张 35元--->3 张 36元--->4 张 37元--->5 张 38元--->4 张 39元--->3 张 40元--->2 张 41元--->3 张 42元--->4 张 43元--->4 张 44元--->3 张 45元--->2 张 46元--->4 张 47元--->4 张 48元--->3 张 49元--->2 张 50元--->1 张 51元--->2 张 52元--->3 张 53元--->4 张 54元--->5 张 55元--->2 张 56元--->3 张 57元--->4 张 58元--->5 张 59元--->4 张 60元--->2 张 61元--->3 张 62元--->4 张 63元--->5 张 64元--->5 张 65元--->3 张 66元--->4 张 67元--->5 张 68元--->5 张 69元--->4 张 70元--->2 张 71元--->3 张 72元--->4 张 73元--->5 张 74元--->4 张 75元--->3 张 76元--->4 张 77元--->5 张 78元--->4 张 79元--->3 张 80元--->2 张 81元--->4 张 82元--->5 张 83元--->5 张 84元--->4 张 85元--->3 张 86元--->5 张 87元--->5 张 88元--->4 张 89元--->3 张 90元--->2 张 91元--->4 张 92元--->5 张 93元--->4 张 94元--->3 张 95元--->2 张 96元--->5 张 97元--->4 张 98元--->3 张 99元--->2 张
点赞
送花
回复 分享
发布于 2016-07-08 11:23
现代汽车中国前瞻数字研发中心
校招火热招聘中
官网直投
我也参加了
点赞
送花
回复 分享
发布于 2016-07-08 00:42

相关推荐

点赞 13 评论
分享
牛客网
牛客企业服务