Doubles


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

分析:用set,检索速度快

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int main(){
set<int> s;
int n, sum;
while(cin >> n){
if(n == -)
break;
sum = ;
s.clear();
s.insert(n);
while(cin >> n){
if(n == )
break;
s.insert(n);
}
set<int>::iterator it = s.begin();
while(it != s.end()){
if(s.find( * (*it)) != s.end())
sum++;
it++;
}
cout << sum << endl;
}
return ;
}

最新文章

  1. 几个MQTT的知识点
  2. 滑动listview隐藏和显示顶部布局
  3. Apache 配置多端口 多虚拟主机 局域网访问
  4. php获取文件mime类型Fileinfo等方法
  5. Qt编译慢吗?
  6. 字符排序(hdoj1106)
  7. 搭建DNS服务
  8. AtCoder Grand Contest 021 D - Reversed LCS
  9. MYSQL——数据库存储引擎!
  10. flask 第二章 endpoint重名 Flask路由 初始化配置 Falsk Config 蓝图+目录结构
  11. PHP全局变量,超全局变量
  12. 程序员装X指南
  13. spring jdbcTemplate 事务,各种诡异,包你醍醐灌顶!
  14. 《算法》第五章部分程序 part 6
  15. TextView显示HTML文本时&lt;IMG&gt;标签指定图片的显示处理
  16. git 重写历史
  17. Mac os x的发展
  18. 从MYSQL数据库查出指定格式的日期
  19. MiCode108 猜数字
  20. 谈谈你对Java平台理解

热门文章

  1. 《Head First HTML与CSS》项目实践中学到的东西
  2. openssl安装介绍
  3. 怎样配置JDK开发环境
  4. sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) Cannot add a NOT NULL column with default value NULL [SQL: u&#39;ALTER TABLE address_scopes ADD COLUMN ip_version INTEGER NOT NULL&#39;]
  5. 一个简单的例子教会您使用javap
  6. Codeforces Round #271 (Div. 2)-B. Worms
  7. spark 省份次数统计实例
  8. c语言产生随机数的方法
  9. 洛谷 P3958 奶酪
  10. 使用jQuery 发送Ajax