天天看点

POJ1552-Doubles

http://poj.org/problem?id=1552

其实直接两重循环枚举数对,然后分别判断前后两倍关系好了,我无聊地排了个序就为了个只判断一次。。。- -#

#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
    int a[20],n,ans,i,j;
    scanf("%d",&a[1]);
    while(a[1]!=-1)
    {
        n=2;
        for(;;n++)
        {
            scanf("%d",&a[n]);
            if(a[n]==0)
            break;
        }
        sort(a+1,a+n);
        ans=0;
        for(i=1;i<=n-1;i++)
           for(j=i+1;j<=n;j++)
              if(a[i]*2==a[j])
                 ans++;
        printf("%d\n",ans);
        scanf("%d",&a[1]);
    }
    return 0;
}      

转载于:https://www.cnblogs.com/YogurtShen/archive/2012/08/28/2660803.html