感觉应该还有更好的算法,反正说就15个数,O(n^2)遍历也无所谓了。。
import java.util.ArrayList;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (true)
{
int n = sc.nextInt();
if (n == -1)
break;
ArrayList<Integer> source = new ArrayList<Integer>();
ArrayList<Integer> res = new ArrayList<Integer>();
while (n != 0)
{
source.add(n);
if (n % 2 == 0)
res.add(n / 2);
n = sc.nextInt();
}
int result = 0;
for (Integer i : res)
for (Integer ii : source)
if (i == ii)
{
result++;
break;
}
System.out.println(result);
}
}
}