网易互娱用java吗_网易互娱:笔试题 - osc_8iux0cyz的个人空间 - OSCHINA - 中文开源技术交流社区...

小学生小明刚刚学会了使用竖式计算三位数乘法,为了更熟练的使用竖式,老师给他布置了N道算术题。但是这个N很多,小明感觉非常不高兴:为什么我不能用计算机去计算这些结果呢?但是作业要求把竖式过程写出来,不能直接写一个结果糊弄老师。

没办法,小明在写作业的时候开始了他的苦衷做乐,,他打算算出今天写到的最多的数字(1,2,3,4,5,6,78,9,小明不喜欢数字0)是哪一个,作为今天的幸运数字,但是小明发现数数字也是一件很麻烦的事情,他想为什么我不能写一个程序去帮我计算这个幸运数字呢?于是小明动起手来。但当他写完识别数字图像识别程序后发现已经很晚了,而作业只写到一半,所以他必须去写乘法竖式。但是眼看12点的钟声就要敲响,小明是在非常想知道今天的幸运数字是什么,于是他拜托你帮忙计算幸运数字,对于小明的竖式乘法,下方说明会有更详细的定义。

输入描述:

每个输入数据包含一个测试点

第一行为一个正整数N(0

接下来N行,每行两个非负整数a,b(0

输出描述:

输出N+1行,前N行每行包括9个使用空格隔开的数字,第i行表示输入中的第i题需要写的数字个数分别是多少。该行第一个数字是数字1写的次数,改行第二个数字是数字2写的次数,一次类推

示例1:

3

123 456

15 20

20 15

输出:

2 2 2 2 3 3 1 3 1

1 1 2 0 1 0 0 0 0

2 2 1 0 1 0 0 0 0

1

说明:

对于123 * 456,竖式乘法如图:

5bd752d58fc09864117d31c68f8fc02d.png

对于两个数字的计算顺序,小明会严格按照先写a在写b,不会点到顺序

importjava.util.ArrayList;importjava.util.List;importjava.util.Scanner;/*** 网易游戏*/

public classProblem11 {public static voidmain(String[] args) {

Scanner sc= newScanner(System.in);int total =sc.nextInt();

List result = new ArrayList<>();

List params = new ArrayList<>(total*2);for (int i = 0; i < total; i++) {

params.add(sc.nextInt());

params.add(sc.nextInt());

}

result=numList(params);for (int i = 0; i < result.size() ; i++) {for (int j = 0; j < result.get(i).length; j++) {

System.out.print(result.get(i)[j]+ " ");

}

System.out.println();

}int max = 0;int n = 1;for (int j = 0; j < total; j++) {

max+= result.get(j)[0];

}for (int i = 1; i < 9; i++) {int another = 0;for (int j = 0; j < total; j++) {

another+=result.get(j)[i];

}if (another >max) {

n= i + 1;

}

}

System.out.println(n);

}//返回两个数乘积后的数字的出现次数集合

public static List numList(Listparams) {

List temp = new ArrayList<>();for (int i = 0; i < params.size()-1; i += 2) {int[] rowResult = new int[9];for (int j = 0; j < rowResult.length; j++) {

rowResult[j]= 0;

}int multiFirst =params.get(i);int multiSec = params.get(i+1);int m = 0;int result = 0;while ((multiSec/10) != 0) {int i1 =result(multiFirst, multiSec, rowResult);if (i1 == -1) {

multiSec= multiSec/10;

m++;continue;

}if (m==0) {

result+=i1;

}else{

result+= i1 * Math.pow(10,m);

}

multiSec= multiSec/10;

m++;

}int i1 =result(multiFirst, multiSec, rowResult);

result+= i1 * Math.pow(10,m);

xunhuan(result, rowResult);

xunhuan(multiFirst,rowResult);

temp.add(rowResult);

}returntemp;

}public static int result (int multiFirst, int multiSec, int[] rowResult) {int yushu = multiSec % 10;if (yushu == 0){return -1;

}

rowResult[yushu-1]++;int i1 = yushu *multiFirst;

xunhuan(i1, rowResult);returni1;

}//计算整数中单个数字出现的次数

public static void xunhuan (int i1, int[] rowResult) {

String i2=String.valueOf(i1);char[] array =i2.toCharArray();for (int j = 0; j < array.length; j++) {if (array[j] - '0' == 0) {continue;

}else{int index = array[j]-'0';

rowResult[index- 1]++;

}

}

}

}

2752407d2ada74faf7716ca82f2de4de.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值