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

  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner sc=new Scanner(System.in);
  7. int i,j,k,sum;
  8. int a[]=new int[16];
  9. while((a[0]=sc.nextInt())!=-1){
  10. i=1;
  11. sum=0;
  12. while((a[i]=sc.nextInt())!=0){
  13. i++;
  14. }
  15. for(k=0;k<i;k++){
  16. for(j=0;j<i;j++){
  17. if(a[k]*2==a[j])
  18. sum++;
  19. }
  20. }
  21. System.out.println(sum);
  22. }
  23. }
  24. }

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

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. How to avoid Over-fitting using Regularization?

    http://www.mit.edu/~9.520/scribe-notes/cl7.pdf https://en.wikipedia.org/wiki/Bayesian_interpretation ...

  2. Mac标识物理位置算法 import Levenshtein mac列表特征值

    mac 字符串 与 基准字符串的 Levenshtein   距离,考虑  mac信号强度的时序性,60秒内若干次变化 不引入强度 mac字符串的唯一性 如何排序 基准字符串的选取 同一尺度 都按强度 ...

  3. thinkphp5, 模板继承、模板布局

    ---------------------------------------------------------------------------------------------------- ...

  4. Django多对多的创建

    1.多对多创建的应用场景: 在某表中创建一行数据是,有一个可以多选的下拉框 例如:创建用户信息,需要为用户指定多个爱好 2.创建方式: 方式一:自定义关系表,手动创建一张表用于关联其他多张表的关系 c ...

  5. Django——自定义分页(可调用)

    1.view from django.shortcuts import render,HttpResponse # Create your views here. from app01.models ...

  6. Data Structure Array: Maximum of all subarrays of size k

    http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/ #include <iostream> #include ...

  7. 【leetcode刷题笔记】Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. P4455 [CQOI2018]社交网络(矩阵树定理)

    题目 P4455 [CQOI2018]社交网络 \(CQOI\)的题都这么裸的吗?? 做法 有向图,指向叶子方向 \(D^{out}(G)-A(G)\) 至于证明嘛,反正也就四个定理,先挖个坑,省选后 ...

  9. HDU2612 -暑假集训-搜索进阶N

     http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/N这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜 ...

  10. JAVA强制类型转换(转载+自己的感想) - stemon

    JAVA强制类型转换(转载+自己的感想) - stemon 时间 2013-10-29 15:52:00  博客园-Java原文  http://www.cnblogs.com/stemon/p/33 ...