zoukankan      html  css  js  c++  java
  • 【hdu 1303 Doubles】

    Doubles

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


    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
     
     
     1 // Project name : 1303 ( Doubles ) 
     2 // File name    : main.cpp
     3 // Author       : Izumu
     4 // Date & Time  : Sun Jul  8 19:20:51 2012
     5 
     6 
     7 #include <iostream>
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     int a[1000];
    13     int top = -1;
    14     int num;
    15     while (cin >> num && num != -1)
    16     {
    17         top = -1;
    18         top++;
    19         a[top] = num;
    20         while (cin >> num && num)
    21         {
    22             top++;
    23             a[top] = num;
    24         }
    25 
    26         // search it to get the answer
    27         int count = 0;
    28         for (int i = 0; i <= top; i++)
    29         {
    30             for (int j = 0; j <= top; j++)
    31             {
    32                 if (a[i] * 2 == a[j])
    33                 {
    34                     count++;
    35                 }
    36             }
    37         }
    38         cout << count << endl;
    39     }
    40     return 0;
    41 }
    42 
    43 // end 
    44 // ism 
  • 相关阅读:
    HashMap死循环造成CPU100%
    ArrayList升级为线程安全的List
    并发容器-ConncurrentHashMap
    并发容器-概览
    不可变性final
    CAS
    原子类-Adder累加器
    hue-使用mysql作为元数据库
    yhd日志分析(二)
    yhd日志分析(一)
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2581776.html
Copyright © 2011-2022 走看看