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. SQL语句创建数据库以及一些查询练习

    --创建 MyCompany数据库 use master execute sp_configure 'show advanced options',1 --开启权限 reconfigure execu ...

  2. 11个炫酷的 Linux 终端命令

    我已经用了十年的Linux了,通过今天这篇文章我将向大家展示一系列的命令.工具和技巧,我希望一开始就有人告诉我这些,而不是曾在我成长道路上绊住我. 1.命令行日常系快捷键 如下的快捷方式非常有用,能够 ...

  3. mysql数据库字段类型的选择原则

    原文链接:http://blog.csdn.net/u013412790/article/details/51615407 数据库类型的选择对数据库的性能影响很大 1 . 数据类型会影响存储空间的开销 ...

  4. ArcGIS中Features与JSON的互相转化

    实际操作过程非常简单,这里就简单记录下转换工具的位置:

  5. logback的configuration

    logback的<configuration>只有三个属性: 1.scan[boolean]:当scan被设置为true时,当配置文件发生改变,将会被重新加载.默认值为true. 2.sc ...

  6. map侧连接

    两个数据集中一个非常小,可以让小数据集存入缓存.在作业开始这些文件会被复制到运行task的节点上. 一开始,它的setup方法会检索缓存文件. 与reduce侧连接不同,Map侧连接需要等待参与连接的 ...

  7. Visual Studio 2015 终于还是装上了

    win8.1系统 vs2015.preview_ult_CHT.iso 大小4.46G, http://download.microsoft.com/download/9/9/1/99133C05-3 ...

  8. 关于Vue生命周期的小记录

    1.created的时候才能获取到data中的属性和methods中的方法 2.特殊情况:beforeCreate中如果是进行了ajax请求,在请求回调中对属性赋值是可以的,因为页面渲染速度比ajax ...

  9. 如何在SAP云平台上使用MongoDB服务

    首先按照我这篇文章在SAP云平台上给您的账号分配MongboDB服务:如何在SAP云平台的Cloud Foundry环境下添加新的Service 然后从这个链接下载SAP提供的例子程序. 1. 使用命 ...

  10. Linux I/O调度

    一) I/O调度程序的总结 1) 当向设备写入数据块或是从设备读出数据块时,请求都被安置在一个队列中等待完成.    2) 每个块设备都有它自己的队列.    3) I/O调度程序负责维护这些队列的顺 ...