Doubles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 4740    Accepted Submission(s): 3259

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.
 
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
 
Source
 
Recommend

Eddy   |   We have carefully selected several similar problems for you:  1200 1302 1339 1312 1301

解题心得:

1、用一个bool标记一下就可以了,主要是要注意一下这个输入的问题。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
bool num[maxn];//看这个数字是否出现过
int Num[maxn];//记录数字
int main()
{
while(1)
{
int t = 0;
bool flag = false;
memset(num,0,sizeof(num));
while(scanf("%d",&Num[t]) && Num[t])
{
if(Num[t] == -1)//出现-1直接标记
{
flag = true;
break;
}
num[Num[t]] = true;
t++;
}
if(flag)//出现-1跳出就可以了
break;
else
{
int cnt = 0;
for(int i=0;i<t;i++)
if(num[Num[i]*2])//这个数字乘以二还在里面
cnt++;
printf("%d\n",cnt);
}
}
return 0;
}

水题:HDU1303-Doubles的更多相关文章

  1. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  5. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  6. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  7. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  8. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

  9. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  10. ACM水题

    ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...

随机推荐

  1. 最简实例演示asp.net5中用户认证和授权(2)

    上接最简实例演示asp.net5中用户认证和授权(1) 基础类建立好后,下一步就要创建对基础类进行操作的类了,也就是实现基础类的增删改查(听起来不太高大上),当然,为了使用asp.net5的认证机制, ...

  2. 批量 多个JPG生产PDF .net C#

    using iTextSharp.text; using iTextSharp.text.pdf; using System; using System.Collections.Generic; us ...

  3. LeetCode(605,581,566)

    LeetCode(605,581,566) 摘要:605盲改通过:581开始思路错误,后利用IDE修改(多重循环跳出方法):566用C语言时需要动态内存分配,并且入口参数未能完全理解,转用C++. 6 ...

  4. 通过 java的 esl 连接 freeswitch

    一.目标修改event_socket配置,使之能够建立远端ESL链接. 二.步骤 1. vim ../autoload_configs/event_socket.conf.xml 2. 默认的监听地址 ...

  5. 【extjs6学习笔记】1.9 初始: Mixins

    Mixin允许我们使用一个类的函数作为另一个类的函数而不继承. Mixins可以使用mixins关键字定义,并将值指定为JSON对象,其中属性的名称应该是要使用的方法的名称,属性的值将是定义方法的类的 ...

  6. TFS无法确定工作区解决方案

    当TFS遇到无法确定工作区时,删除掉SUO和VSSSCC文件,当然也有可能不是这两个,反正是SLN文件以外的两个文件,毕竟是昨天做的事,有点忘记了.所以,做掉文件之前,要做好备份O(∩_∩)O~

  7. MAC MAMP install yaf

    Yaf doesn't support PHP 5.6! You may see this: Warning: PHP Startup: yaf: Unable to initialize modul ...

  8. Weblogic 10.3.6.0 集群搭建

    Weblogic 集群搭建 Oracle的Weblogic分开发者版本和生产版本,有32位和64位.一般生产版本的weblogic是64位的,安装文件是一个大小为1G多的jar包.去oracle官网上 ...

  9. JavaScript getMonth() 方法

    应该特别注意的是Js中getMonth()这个方法的返回值: 定义和用法: getMonth() 方法可返回表示月份的数字. 返回值: dateObject 的月份字段,使用本地时间.返回值是 0(一 ...

  10. IOS截取部分图片

    截取部分图片这么简单: - (void)loadView {     [[UIApplication sharedApplication] setStatusBarHidden:YES withAni ...