B - Doubles(1.2.1)

这道题可把我憋死了,哎!刚开始定义a【15】,运行错误,无语呀!!!!!

Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d
& %I64u

Submit Status

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.

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
#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a[100],i,n,j,k;;
cin>>a[0];
	while(a[0]!=-1)
	{
	i=1;

	n=0;

	while(a[0]&&cin>>a[i]&&a[i])
	{
		i++;
	}

	for(j=0;j<=i;j++)
		for(k=j+1;k<=i;k++)
			if(2*a[j]==a[k]||a[j]==2*a[k])
			{n++;}

    cout<<n<<endl;
	cin>>a[0];
	}

return 0;
}

B - Doubles(1.2.1)

时间: 2024-11-01 11:21:32

B - Doubles(1.2.1)的相关文章

hdu 1303 Doubles

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1303 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 i

杭电 HDU ACM 1303 Doubles

Doubles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3805    Accepted Submission(s): 2646 Problem Description As part of an arithmetic competency program, your students will be given randoml

POJ 1552 Doubles 水

Doubles Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20106   Accepted: 11667 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 as

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 i

ZOJ 1760 Doubles

Doubles Time Limit: 2 Seconds      Memory Limit: 65536 KB 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 ar

(HDU)1303 -- Doubles(两倍)

题目链接:http://vjudge.net/problem/HDU-1303 合适的处理输入,把数据读入数组,对数组升序排序(减少循环次数) 用一个双重循环看每一个数,判断是不是前面出现的数的两倍. #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <string> #incl

poj 1552 Doubles

1 #include <stdio.h> 2 #include <stdlib.h> 3 int nums[16]; 4 5 int cmp(const void *a, const void *b) 6 { 7 return *(int*)a - *(int*)b; 8 } 9 10 int main() 11 { 12 int n,i,j,result; 13 while(scanf("%d",&n) && n != -1) 14 {

杭电ACM1303——Doubles

这一题,水题.题目的意思是输入一个数组,判断数组中有多少对是 a * 2 = b的,a和b都是数组中的数. 只是输入时比较麻烦,注意一下就好了. 下面的是AC的代码: #include <iostream> using namespace std; int main() { int num[20]; int i, j = 0; while(cin >> i) { if(i == 0) { int count = 0; for(int a = 0; a < j; a++) {

ZOJ 1760 &amp;&amp;POJ1552 Doubles (模拟)

链接:click here 题意:叫你求一个数是另一个数的二倍的这样的组合有多少个. 思路:纯模拟,一重循环:读入当前数据组a,并累积数据元素个数n,循环的结束标志是读入数据0,两重循环结构枚举组内所有数据对a[i] a[j] 判断是否成两倍关系 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm>