HDU 1303 Doubles(水题)

网友投稿 899 2022-08-23

HDU 1303 Doubles(水题)

HDU 1303 Doubles(水题)

Doubles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4461    Accepted Submission(s): 3072

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

​​Mid-Central USA 2003​​

题解:计算有多少对是互为双倍的数。。。

AC代码:

#include#include#include#include#include#include#include#includetypedef long long LL;using namespace std;int n[201];int main(){ int t; char c; while(cin>>t,t+1){ memset(n, 0, sizeof(n)); n[t]=1; while(cin>>t,t) n[t]=1; int count = 0; for(int i = 0; i < 200; i++) if(n[i]) if(n[2 * i]) count++; cout << count <

AC2: 用vector。

#include#include#includeusing namespace std;int main(){ int temp; while(cin>>temp&&temp!=-1) { vector v; v.push_back(temp); while(cin>>temp&&temp!=0) v.push_back(temp); int sum=0; for(int i=0;i!=v.size();++i) { auto b=find(v.cbegin(),v.cend(),2*v[i]); if(b!=v.cend()) sum++; } cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:前后端分离了,然后呢?(什么前后端分离)
下一篇:HDU 1326 Box of Bricks(水题)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~