您的位置:首页 > 其它

hdu 1303 Doubles

2015-09-24 19:27 423 查看
题意:一个序列中是倍数关系的倍数对有多少个?

注意:这是一道水题。

代码实现:

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
Mid-Central USA 2003


Recommend
Eddy | We have carefully selected several similar problems for you: 1200 1339 1301 1304 1305
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: