一、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 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.

二、题解

        水题啊,今天把水题都做完了,以后我要怎么办啊!!

三、Java代码

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i,j,k,sum;
int a[]=new int[16];
while((a[0]=sc.nextInt())!=-1){
i=1;
sum=0;
while((a[i]=sc.nextInt())!=0){
i++;
}
for(k=0;k<i;k++){
for(j=0;j<i;j++){
if(a[k]*2==a[j])
sum++;
}
}
System.out.println(sum);
}
}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Poj 1552 Doubles(水题)的更多相关文章

  1. POJ.1552 Doubles(水)

    POJ.1552 Doubles(水) 题意分析 暴力 代码总览 #include <cstdio> #include <stdio.h> #define nmax 100 u ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  4. POJ 1552 Doubles (C++ STL set使用)

    题目: 题意:题意:给出几个正数(2~15个),然后就是求有这些数字的2倍有没有和原先的正数相同的,求出有几个,没有就是0. 分析:水题.用数组解决,开一个数组存正数,另开一个数组用来存这些数的2倍, ...

  5. 最小费用最大流模板 poj 2159 模板水题

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15944   Accepted: 8167 Descr ...

  6. POJ 1837 Balance 水题, DP 难度:0

    题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...

  7. POJ - 3090 gcd水题

    大概题意就是求\(1 \le i,j \le n\)的\(gcd(i,j) = 1\)的个数+2(对于0的特判) 正解应该是欧拉函数或者高逼格的莫比乌斯反演 但数据实在太水直接打表算了 /*H E A ...

  8. POJ 1654 Area(水题)

    题目链接 卡了一下精度和内存. #include <cstdio> #include <cstring> #include <string> #include &l ...

  9. poj 1552 Doubles

    #include <stdio.h> #include <stdlib.h> ]; int cmp(const void *a, const void *b) { return ...

随机推荐

  1. 【python】-- 类的装饰器方法、特殊成员方法

    装饰器方法 类的另外的特性,装饰器方法:静态方法(staticmethod).类方法(classmethod).属性方法(property) 一.静态方法 在方法名前加上@staticmethod装饰 ...

  2. 6.让ORM映射执行的时候打印SQL语句

    配置Django日志:\hello_django\hello_django\settings.py 文件中的 LOGGING 加入如下配置: LOGGING = { 'version': 1, 'di ...

  3. ABAP内表数据做层次XML输出

      *&---------------------------------------------------------------------**& Report  Z_BARRY ...

  4. Windows磁盘MBR结构详解

    在之前的文章 Windows存储管理之磁盘结构详解 中介绍了Windows的磁盘结构和MBR.本文将对Windows Basic Disk中的MBR的结构进行介绍,帮助读者更好的了解Windows系统 ...

  5. QT5的QDesktopSerivices不同

    QT4使用QDesktopServices::storageLocation(QDesktopServices::xxxx)来获取一些系统目录, 现在则要改成QStandardPaths::writa ...

  6. html ---- web sql 例子

    <!doctype html> <html> <head> <meta charset="utf-8"> <script> ...

  7. 2018年长沙理工大学第十三届程序设计竞赛 C 取手机 【概率】

    链接:https://www.nowcoder.com/acm/contest/96/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  8. linux mint console-setup

    sudo dpkg-reconfigure console-setup after setup, setupcon

  9. 如何彻底禁止手机连接usb,代码实…【转】

    本文转载自:https://blog.csdn.net/jun4331247/article/details/51201825 作为系统第三次被黑的修复方法,捯饬了半天,没效果,最后大神一出手,果然出 ...

  10. GetTickCount的几个案例

    一,获得运行时间: var T1,T2 : double; begin T1 := GetTickCount; //需要做的事情 T2 := GetTickCount; ShowMessage( fl ...