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

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

最新文章

  1. STM32F412应用开发笔记之六:使用片上Flash存储参数
  2. JAligner的一个坑
  3. Neutron Vlan Network 原理- 每天5分钟玩转 OpenStack(92)
  4. python实现排序算法
  5. UVA 11235 频繁出现的数值 RMQ
  6. Ant自动编译打包&amp;发布 android项目
  7. 编译spock proxy
  8. 信驰达携“Zigbee Light Link灯控方案”亮相第18届广州国际照明展
  9. 单行bash、shell、perl命令
  10. 2015.1写留言板的时用的 知识点和函数 ---&gt;总结
  11. WPF界面设计技巧(3)—实现不规则动画按钮
  12. Mutex 实现进程独占资源
  13. cookie和session的区别(搜狐笔试考到的一个题目)
  14. Bootstrap fileinput:文件上传插件的基础用法
  15. Centos 7防火墙firewalld开放端口
  16. P2024 食物链
  17. 初识kafka
  18. 简单JAVA爬虫51Jobs
  19. Logstash收集nginx访问日志和错误日志
  20. 【深入spring】IoC容器的实现

热门文章

  1. struts2 获取表单数据封装到list和map集合
  2. android 中使用svg
  3. linux 中 用户管理 (composer 时不能root 遇到)
  4. 搜索ABAP程序代码中的字符串
  5. QT设置QToolBar带有图标和文字
  6. 数据库基本表创建 完整性约束 foreign Key
  7. [原创]Scala学习:编写Scala脚本
  8. &lt;a href
  9. hiho一下 第四十八周 拓扑排序&#183;二【拓扑排序的应用 + 静态数组 + 拓扑排序算法的时间优化】
  10. Spring Boot- 用idea新建spring boot web项目