zoukankan      html  css  js  c++  java
  • Poj 1552 Doubles(水题)

    一、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 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.
    二、题解
            水题啊,今天把水题都做完了,以后我要怎么办啊!!
    三、Java代码
    import java.util.Scanner;
    
    public class Main {
    	
        public static void main(String[] args) { 
        	Scanner sc=new Scanner(System.in);
        	int i,j,k,sum;
        	int a[]=new int[16];
        	while((a[0]=sc.nextInt())!=-1){
        		i=1;
        		sum=0;
        		while((a[i]=sc.nextInt())!=0){
        			i++;
        		}
        		for(k=0;k<i;k++){
        			for(j=0;j<i;j++){
        				if(a[k]*2==a[j])
        					sum++;
        			}
        		}
        		System.out.println(sum);
        	}
        }
    } 


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Mint13的人性化改造
    [51单片机]18b20驱动函数
    应用三菱GX Developer编程软件编写SFC顺序功能图的方法
    [MATLAB]all()函数的使用
    基于RaspberryPi和Python的智能远程控制原型
    《哈佛大学公开课:幸福课》学习笔记(2)
    《哈佛大学公开课:幸福课》学习笔记(3)
    How to create a custom Ubuntu live from scratch
    网络3
    7/13/2021python 核心编程020215
  • 原文地址:https://www.cnblogs.com/AndyDai/p/4734163.html
Copyright © 2011-2022 走看看