您的位置:首页 > 其它

ZOJ-1760

2013-12-19 21:00 183 查看
感觉应该还有更好的算法,反正说就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);
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: