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);
        }
    }

}
时间: 2024-11-13 03:57:07

HDOJ 1303 Doubles(简单题)的相关文章

ZOJ 简单题集合

这部分题由于过于简单,属于白送题目,因此把所有特别简单题的合集于此. 1048:统计某人12个月的银行帐户余额的平均数.(简单的令人汗!) Code_1048/*ZOJ 1048: 统计小数的平均数!居然就是12个double求平均数..汗!*/ #include <stdio.h>double balance[12];int main() {  int i;  double sum=0,aver;  for(i=0;i<12;i++)  {   scanf("%lf"

c语言编程-关于C语言字符串的简单题求助

问题描述 关于C语言字符串的简单题求助 进行对输入的字符串重新排列,要求字母在前,数字在后,并不改变字母和数字之间的字符排列顺序. 解决方案 #include void main() { char a[10] = {0}, b[10] = {0}, c[10]={0}; int n = 0, m = 0, k = 0,f = 0; printf("输入字符串:"); gets(a); for(int j = 0; j < 10; j++) { if((a[j] >= 'a'

ZOJ 简单题集合(二)

对以下简单题,我同时给出一个我主观认为的难度值(0.1~1.0之间). (1). ZOJ 1072: Microprocessor Simulation. (Difficulty: 0.2) http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1072 微处理器模拟,它含有两个累加器,代码和内存统一寻址,即冯诺依曼结构,比较简单. ZOJ1072_cpp #include <stdio.h>#include <stri

HDOJ 1326 Box of Bricks(简单题)

Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. Look, I've built a wall!'', he tells his older sister Alice.Nah, you should make all stacks the same heigh

HDOJ 1323 Perfection(简单题)

Problem Description From the article Number Theory in the 1994 Microsoft Encarta: "If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not 1/-1, b is called a proper di

HDOJ/HDU 2568 前进(简单题)

Problem Description 轻松通过墓碑,进入古墓后,才发现里面别有洞天. 突然,Yifenfei发现自己周围是黑压压的一群蝙蝠,个个扇动翅膀正准备一起向他发起进攻! 形势十分危急! 好在此时的yifenfei已经不是以前那个经常被lemon抢走MM的菜鸟了!面对众多蝙蝠的嗜血狂攻,只见yifenfei使出轻灵的剑法,刷,刷,刷,瞬间搞定-- 现已知yifenfei使用了2招(剑招A和剑招B):剑招A,一招能杀死一半的蝙蝠.但是如果当前的蝙蝠数为奇数,那么就必须先出一招剑招B杀死其中

HDOJ(HDU) 2123 An easy problem(简单题...)

Problem Description In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j. Input The first line of input is an integer C which indicate the

多家地方电视台播猜谜节目简单题骗高话费

新京报制图/丁华勇吉林卫视播出的电视猜谜节目.青海卫视播出的电视猜谜节目. 一边是高额现金大奖,一边是简单得看一眼就能知道答案的猜谜题目.近来,此类有奖竞猜节目出现在不少电视台的清晨和午夜时段,丰厚的奖项,加上主持人"快拿起电话,5000元大奖就是你的."的诱惑,吸引不少观众参与.但真正打过电话的人,都大呼"上当". 6月29日凌晨1时30分许,几家地方卫视频道不约而同的播出电视猜谜节目."什么酒需要两个人一起喝?"节目中不断有语音提示"

ZOJ 简单题集合(四)

(1)ZOJ 1016. Parencodings 题意:把一个括号表达式 S,从 P 编码转换为 W 编码. P 编码:P = P1,P2, ... , Pn; 其中 Pi  是 S 的第 i 个右括号前面的左括号个数. W 编码:W = W1, W2, ... , Wn; 对于 S 中的某一个右括号 a,Wi 是从与 a 匹配的左括号开始数起,数到 a 为止的右括号个数.   例如:S (((()()())))P-编码: 4 5 6 6 6 6:W-编码: 1 1 1 4 5 6:   分析