HDOJ 1303 Doubles(简单题)
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 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.
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. No integer will be larger than 99. Each line will be terminated with the integer 0, which is not considered part of the list. A line with the single number -1 will mark the end of the file. 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
题意:就是判断输入的一行数中,有多少对数字相差2倍。
输入的数据不会有重复的。
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String strNum = sc.nextLine();
String[] strsNum = strNum.split(" ");
int[] num = new int[strsNum.length];
for(int i=0;i<strsNum.length;i++){
num[i] = Integer.parseInt(strsNum[i]);
}
if(num[0]==-1){
return ;
}
int t=0;
for(int i=0;i<num.length;i++){
for(int j=0;j<num.length;j++){
if(i!=j){
//注意除数不能为0!
if(num[j]!=0){
double two = (num[i]*1.0)/(1.0*num[j]);
if(two==2){
t++;
break;
}
}
}
}
}
System.out.println(t);
}
}
}
HDOJ 1303 Doubles(简单题)的更多相关文章
- hdu 1303 Doubles
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1303 Doubles Description As part of an arithmetic com ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 这样leetcode简单题都更完了
这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- 团体程序设计天梯赛-练习集L1-014. 简单题
L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...
随机推荐
- Ubuntu 13.04 安装 GCC4.8.1
终于有了完整实现C++11的GCC 4.8.1. 给自己的系统升级吧. 下面的步骤可以安装GCC4.8.1, 内容来自:http://askubuntu.com/questions/312620/ho ...
- cocos2d-3.0 Helloworld::onTouchMoved的处理机制的推測
bool sign2 = true; bool sign2 = true; void GameLayer::onTouchMoved(Touch *touch, Event *unused){ if( ...
- Meth | ubuntu下安装与卸载软件方法
1.通过deb包安装的情况: 安装.deb包: 代码:sudo dpkg -i package_file.deb反安装.deb包:代码:sudo dpkg -r package_name 2.通过ap ...
- 第二章:开始开发mod前你需要知道的一些事情
<基于1.8 Forge的Minecraft mod制作经验分享> 是的童鞋,别着急.不管我写的再认真也不可能面面俱到,那么如果遇到了什么问题怎么办呢?所以咱必须先掌握一些基础的东西,这样 ...
- Android - 硬件抽象层(HAL)
以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luosheng ...
- sql server根据日期或者月份查询聚合数据
/*****************************根据时间查询每天的数据***************************************/ @tm_start:开始时间 @tm ...
- mysql explain 命令解释
转载http://bzyyc.happy.blog.163.com/blog/static/6143064720115102551554/ key实 际使用的索引.如果为NULL,则没有使用索引.很少 ...
- PHP Calendar 函数
PHP 5 Calendar 函数 函数 描述 cal_days_in_month() 针对指定的年份和历法,返回一个月中的天数. cal_from_jd() 把儒略日计数转换为指定历法的日期. ca ...
- mysql数据表如何导入MSSQL中
本案例演示所用系统是windows server 2012.其它版本windows操作系统类似. 1,首先需要下载mysql odbc安装包. http://dev.mysql.com/downloa ...
- 使用nw.js将html项目打包为桌面程序
首先需要确保电脑已经布置好node.js环境 1.下载并全局安装nw.js npm install nw -g 2.安装nw-builder模块 npm install nw-builder -g 3 ...