POJ 1552 Doubles

题目链接:http://poj.org/problem?id=1552

有好多天不写了,手有点生,今天算是捡个简单的练练手,不少东西都忘记了,写起来就不那么得心应手,这个题我觉得题意并不难,对我来说,难就难在输入上,话不多说了,看代码吧:

#include<iostream>
#include<stdio.h> 
using namespace std;
int main()
{
	int a[16],n,c,x;
	for(int i = 0;;i++)
	{
		scanf("%d",&n);
		if(n == -1)	break;
		else
		{
			a[0] = n;
			for(int j = 1;;j++)
			{
				scanf("%d",&a[j]);
				if(a[j] == 0)	break;
				x = j;
			}
			int ans = 0;
			for(int k = 0;k <= x; k++)
			{
				for(int l = 0;l <= x; l++)
				{
					if(a[l] * 2 == a[k])
						ans++;
				}
			}
			cout << ans << endl; 
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/xiao__hei__hei/article/details/81266239