Doubles
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18824   Accepted: 10846

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.

Sample Input

  1. 1 4 3 2 9 7 18 22 0
  2. 2 4 8 10 0
  3. 7 5 11 13 1 3 0
  4. -1

Sample Output

  1. 3
  2. 2
  3. 0

Source

Mid-Central USA 2003
  1. #include <iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a[];
  8. cin>>a[];
  9. while(a[]!=-)
  10. {
  11. int n =;
  12. int ans = ;
  13. for(;;n++)
  14. {
  15. cin>>a[n];
  16. if(a[n]==)
  17. break;
  18. }
  19. for(int i=;i<n-;i++)
  20. {
  21. for(int j=i+;j<n;j++)
  22. if(a[i]*==a[j]||a[i]==a[j]*)
  23. ans++;
  24. }
  25. cout<<ans<<endl;
  26. memset(a,,sizeof(a));
  27. cin>>a[];
  28. }
  29. return ;
  30. }

poj1552的更多相关文章

随机推荐

  1. <php>统计整个文件夹的大小

    //用来统计一个目录下大小 function dirsize($file) { $size = 0; $dir = opendir($file); while($filename = readdir( ...

  2. maven install 报错Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin

    Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of ...

  3. python3-day5(模块)

    1.获取路径import os,sys #获取全部路径 print(os.path.abspath(__file__)) #获取目录 print(os.path.dirname(os.path.abs ...

  4. HDU1285——确定比赛名次

    Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...

  5. IOS 6.0+ Autolayout — UITableViewCell 高度调整

    要实现的效果 要求: storyboard上的准备工作 建好cell自定义AutoCell 类,关联好控件,事先准备好一些数据源 实现tableview的委托方法 核心部分,HeightForRow方 ...

  6. Java Builder模式 体验(二)

       在上篇文章中,对Java Builder模式的使用体验主要是从Builder对构造器改造方面的优秀特性来说的,感觉并没有从Java Builder模式本身的功能和作用去写,因此决定再从Build ...

  7. asp net 编程问题 实现下一篇 和上一篇效果

    首先是access数据库,有一个名为news的表,里面有三个字段,分别为id,classid 和name 其中id为主键,classid可以重复 现在有以下数据: id classid name 1 ...

  8. oracle服务的开始和关闭 CMD

    开始: @echo halt oracle service ...net start OracleServiceORCLnet start OracleOraDb11g_home1TNSListene ...

  9. struts 标签引用出错

    几句句话概括 1.检查 web.xml  出现错误自己改 配置后filter  jsp-config 2.检查 tld 目录下的东西 是否缺少 3. 将包复制到web的lib目录下后    之后  b ...

  10. <转> 纸牌屋1-4集分析

    原文:http://blog.sina.com.cn/s/blog_b86c61490102v56t.html 第一季第一集 主人公弗兰克的出场,是以对待一只邻家将死之狗的态度展开的,充分显示了主人公 ...