Doubles

Time Limit: 1000MS Memory Limit: 65536KB

Problem 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 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.

Example Input

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

Example Output

3
2
0 题目意思找输入数字中的2倍关系:
注意:推荐用乘法以避免除以0的尴尬。 代码:
#include <cstdio>
#include <string>
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int compare(const void*a,const void*b)
{
return *(int*)a - *(int*)b;
}
int main(int argc, const char * argv[]){
int nums[], i, count;
while () {
count = i = ;
while (scanf("%d", &nums[i])) {
if (nums[i] == -) {
return ;
}
i++ ;
if (getchar() == '\n') {
break;
}
}
qsort(nums, i, sizeof(int), compare);
for (int j = ; j < i; j++) {
for (int k = j - ; k > -; k--) {
if (nums[k] * == nums[j]) {
count ++;
} else if(nums[k] * < nums[j]) {
break;
}
}
}
printf("%d\n", count);
}
return ;
}
//0ms 148kb g++ 930B

最新文章

  1. Ngnix下安装python2.7
  2. 织梦cms、帝国cms、PHPcms优缺点解析
  3. GEF: 图形拖拽处理
  4. Android抓包方法(二)之Tcpdump命令+Wireshark
  5. ubunto安装pycharm
  6. memache session
  7. Javascript Date类常用方法详解
  8. C# Lambda Expressions 简介
  9. WPF之小动画三
  10. HTML5 canvas标签绘制正三角形 鼠标按下点为中间点,鼠标抬起点为其中一个顶点
  11. OJ python答题结果&quot;返回非零&quot;
  12. WKE——Webkit精简的纯C接口的浏览器
  13. 《JS权威指南学习总结--6.6属性getter和setter》
  14. 【学习总结】GirlsInAI ML-diary day-15-读/写txt文件
  15. 如何在Idea提交代码到Github上
  16. [C]内存管理、内存泄露、堆栈
  17. Java 微服务框架选型 Dubbo 和 Spring Cloud
  18. 2017/05/21 java 基础 随笔
  19. 远程阿里云window服务器报错身份验证错误
  20. 【BZOJ2658】[Zjoi2012]小蓝的好友(mrx) 平衡树维护笛卡尔树+扫描线

热门文章

  1. Redhat YUM U盘源配置
  2. 在ModelSim波形图中以参数名显示变量
  3. (转) ASP.NET页面缓存
  4. Linux基础1之磁盘与分区
  5. WebView支持特效,页面内跳转(转载!)
  6. php注册登录时生成的验证码
  7. Eclipse 配置SSH 详解
  8. Android中一般支持的常用的距离单位
  9. struts2框架加载配置文件的顺序
  10. IDE开发&lt;LER-Studio&gt;(2)::登录模块