• zoj 1760 Doubles(set集合容器的应用)


    题目链接:

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1760

    题目描述:

    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

     1 /*问题 求一串数字中存在谁是谁的两倍的关系的个数
     2 解题思路 问题很简单,主要是使用了STL中的set集合,查询起来速度是极快的。*/ 
     3 #include <set>
     4 #include <cstdio>
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int n,sum;
    10     set<int> s;
    11     set<int>::iterator it;
    12     while(1)
    13     {
    14         scanf("%d",&n);
    15         if(n == -1) break;
    16         if(n == 0)
    17         {
    18             sum=0;
    19             for(it=s.begin(); it != s.end();it++){
    20                 if(s.find(2*(*it)) != s.end())
    21                     sum++;
    22             }
    23             printf("%d
    ",sum);
    24             s.clear();
    25         }
    26         else
    27             s.insert(n);
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    iphoneX 兼容
    app 判断网络状态
    app 版本升级
    express 安装
    app打开QQ与陌生人聊天
    app项目中几个常用的cordvoa插件
    axios请求拦截器和相应拦截器
    vue中MD5+base64加密
    想啥写啥
    react canvas圆环动态百分比
  • 原文地址:https://www.cnblogs.com/wenzhixin/p/8543671.html
Copyright © 2020-2023  润新知