第一届河北高校IT联盟2020新春挑战赛 2020-2-1 13:00 3.2 hours

1.新年游戏

Description

大年初一,虽然不像往年一样鞭炮声连绵不绝,但群内外依然充满了着快活的空气。“滑稽,你当真懂算法吗?”。滑稽看着问他的人,显出不屑置辩的神气。他们便接着说道,“你怎的连半个奖牌也捞不到呢?” 滑稽气急,惊慌到:“莫非你们比我懂?那我便出题考考你们!”。

统计n个a与m个b相乘(形如aaaaa*bbb)的乘积中有几个d。

a,b,d均为个位数,注意数据范围。

Input

第一行数据数据组数t,

接来下t行每行五个整数依次为a、n、b、m、d。

t<=5000t <= 5000t<=5000

0<=a,b,d<=90 <= a, b, d<= 90<=a,b,d<=9

0<=n+m<=180 <= n + m <= 180<=n+m<=18

Output

每行输出一个整数,表示n个a与m个b的乘积中d的个数。共输出t行

Sample Input 1

1
2 3 4 5 6

Sample Output 1

3

Hint

222*44444 = 9866568,其中有3个6

Source

河北高校IT联盟群审题小组

//以下代码Runtime error,但是本着“从错误中吸取经验教训”的原则,把今后需要注意的内容以注释的形式展现了出来,见下:
import java.util.Scanner;

public class HowManyShuZi {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			int a = sc.nextInt();
			int n = sc.nextInt();
			int b = sc.nextInt();
			int m = sc.nextInt();
			int d = sc.nextInt();
			int yz_one = 0;
			int yz_two = 0;
			for (int x = 0; x < n; x++) {
				int one = (int) (a * Math.pow(10, x));
				yz_one += one;
			}
			for (int y = 0; y < m; y++) {
				int two = (int) (b * Math.pow(10, y));
				yz_two += two;
			}
			int jg = yz_one * yz_two;
			int weishu = 0;
			int temp = jg;
			while (jg != 0) {
				jg /= 10;
				weishu++;
			}
			//temp是一个数字
			String str = Integer.toString(temp);
			int count=0;
			for (int j = 0; j < str.length(); j++) {
//				str.char()返回的是字符,而等号右边是int,所以结果是0,经调试后(+‘0’),正确
//				char==int(ASCII) eg:‘6’(char)==6+48(int)  ==> 48+6==6+48 count++;  
//				if (str.charAt(j)==(d+'0')) {
//					count++;
//				}
//				或:
				if ((str.charAt(j)-'0')==d) {
					count++;
				}
			}
			System.out.println(count);
		}

	}
}

控制台:
1
2 3 4 5 6
3

2.组队出征

Description

随着程序设计竞赛的推广,河北众院校也开始积极组织队伍参加新的一年的程序设计竞赛。众所周知,XCPC赛制由三人组队参加,在组队时三名队员应该各有所长,互补短板,互相配合完成比赛。

现在我们把每个备选队员的各项能力数值化,一支队伍的各项能力的数值为三名队员中该项能力最高的数值,一支队伍的短板为该队伍各项数值中的最低值。现在要你从n名备选队友中选出三人组成一支队伍,使得这支队伍的短板数值最大,求该队伍的短板数值x。

Input

第一行输入两个整数n、m,分别表示备选人数,以及能力数值个数。

接下来n行,每行输入m个整数a1a_{1}a1​到ama_{m}am​,为每一名队员的各项能力数值。

3<=n<=10^5

1<=m<=6

0<=ai<=10^6

Output

输出一个整数x为最大的短板数值

Sample Input 1

3 3
10 1 1
1 9 1
1 1 8

Sample Output 1

8

Sample Input 2

4 4
1 1 1 10
1 1 10 1
1 10 1 1
10 1 1 1

Sample Output 2

1

Source

河北高校IT联盟群审核小组

//以下代码只是为了通过此题积累将二维数组存储到一维数组中的知识缺陷,并非题目正解。
import java.util.Arrays;
import java.util.Scanner;

public class TwoArrayToOneArray {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] ia1=new int[n*m];
		int[][] ia2=new int[n][m];
		int i=0;
		int j=0;
		for ( i = 0; i < ia2.length; i++) {
			for ( j = 0; j < ia2[0].length; j++) {
				ia2[i][j]=sc.nextInt();
				//二维数组转成一维数组:a[i*M+j] i是行下标,M是一列的元素个数,j是列下标
				ia1[i*m+j]=ia2[i][j];
			}
		}
		for (int k = 0; k < ia1.length; k++) {
			System.out.println(ia1[k]);
		}
	}
}

控制台:
2 3
8 7 6
3 2 1
8
7
6
3
2
1
补:
二维数组转一维数组图解:
在这里插入图片描述

发布了27 篇原创文章 · 获赞 2 · 访问量 949

猜你喜欢

转载自blog.csdn.net/wcy8733996wcy/article/details/104141336
3.2