(HDU)1303 -- Doubles(两倍)

题目链接:http://vjudge.net/problem/HDU-1303

合适的处理输入,把数据读入数组,对数组升序排序(减少循环次数)

用一个双重循环看每一个数,判断是不是前面出现的数的两倍。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
    int i,j,temp,num[10010],cnt;
    while(~scanf("%d",&temp))
    {
        if(temp==-1) break;
        int ans=0;
        num[1]=temp;
        for(cnt=2;;cnt++)
        {
            scanf("%d",&temp);
            if(temp==0) break;
            num[cnt]=temp;
        }
        cnt--;
        sort(num+1,num+1+cnt);
        if(cnt==1) printf("0\n");
        for(i=2;i<=cnt;i++)
            for(j=1;j<i;j++)
                if(num[i]==num[j]*2) ans++;
        printf("%d\n",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/ACDoge/p/6135576.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值