OpenJ

mac2024-07-03  146

OJ地址:https://vjudge.net/problem/OpenJ_Bailian-2807

给定2到15个不同的正整数,你的任务是计算这些数里面有多少个数对满足:数对中一个数是另一个数的两倍。 比如给定1 4 3 2 9 7 18 22,得到的答案是3,因为2是1的两倍,4是2个两倍,18是9的两倍。

Input

一行,给出2到15个两两不同且小于100的正整数。最后用0表示输入结束。

Output

一个整数,即有多少个数对满足其中一个数是另一个数的两倍。

Sample Input

1 4 3 2 9 7 18 22 0

Sample Output

3

程序代码:

#include<cstdio> int main(){ int a[16]; int n,x=0,count=0; while(scanf("%d",&n)&&n){ a[x++]=n; } for(int i=0;i<x;i++){ for(int j=0;j<x;j++){ if(a[i]*2==a[j]){ count++; } } } printf("%d\n",count); return 0; }

运行结果:

最新回复(0)