hdu 1303 Doubles

本文介绍了一个用于计数一个整数列表中倍数对数量的程序。该程序旨在帮助评估学生的数学作业,通过检查列表中是否存在某个数字是另一个数字两倍的情况。文章提供了完整的Java代码实现,并解释了其工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:一个序列中是倍数关系的倍数对有多少个?

注意:这是一道水题。


代码实现:

import java.util.Scanner;

public class p1303 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int arr[] = new int[105];
		while (sc.hasNext()) {
			String str = sc.nextLine();
			String[] strs = str.split(" ");
			if (strs.length == 1) {
				break;
			}
			// 初始化数据
			for (int i = 0; i < arr.length; i++) {
				arr[i] = 0;
			}
			// 用下标表示值
			for (int i = 0; i < strs.length - 1; i++) {
				int temp = Integer.parseInt(strs[i]);
				arr[temp] = 1;
			}
			// 判断倍数
			int count = 0;
			for (int i = 1; i < 50; i++) {
				if (arr[i] == 1 && arr[i * 2] == 1) {
					count++;
				}
			}
			System.out.println(count);
		}
	}

}



Doubles

倍数
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4060    Accepted Submission(s): 2825


Problem Description
As part of an arithmetic competency program, 
算数作为能力大纲的一部分,
your students will be given randomly generated lists of from 2 to 15 unique positive integers 
你的学生可能得到2-15个随机数。
and asked to determine how many items in each list are twice some other item in the same list. 
你的任务是记录从当前列表中找到一个数是另一个数的倍数个数。
You will need a program to help you with the grading. 
你将需要一个程序来帮助你给学生打分。
This program should be able to scan the lists and output the correct answer for each one. 
这个程序有两个功能必须实现,第一个是把列表数据显示,第二个是显示正确的答案。
For example, given the list 
举一个例子:
1 4 3 2 9 7 18 22

your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18 is twice 9.
 你的程序应该显示3,因为2是1的倍数,4是2的倍数,18是9的倍数。

Input
The input file will consist of one or more lists of numbers. There will be one list of numbers per line. 
输入文件包含多组测试事件,每一个测试事件都是一行。
Each list will contain from 2 to 15 unique positive integers. 
每一个测试事件中包含的整数的范围是2-15,且每一个数都不相同。
No integer will be larger than 99. 
最大的数不会超过99.
Each line will be terminated with the integer 0, which is not considered part of the list. 
每一行的最后一个元素是0,他是行结束标志,不计算在列表中。
A line with the single number -1 will mark the end of the file. 
文件的末尾用-1标记。
The example input below shows 3 separate lists. 
比如说下列三组测试数据。
Some lists may not contain any doubles.
 一个测试事件中可能不包含倍数。

Output
The output will consist of one line per input list, containing a count of the items that are double some other item.
 输出这个测试事件中倍数的总个数。

Sample Input
  
1 4 3 2 9 7 18 22 0 2 4 8 10 0 7 5 11 13 1 3 0 -1
 

Sample Output
  
3 2 0
 

Source
 

Recommend
Eddy   |   We have carefully selected several similar problems for you:   1200  1339  1301  1304  1305 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值