码迷,mamicode.com
首页 > 其他好文 > 详细

(HDU)1303 -- Doubles(两倍)

时间:2016-12-05 23:05:29      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:int   str   net   div   class   return   namespace   sort   链接   

题目链接: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;
}

 

(HDU)1303 -- Doubles(两倍)

标签:int   str   net   div   class   return   namespace   sort   链接   

原文地址:http://www.cnblogs.com/ACDoge/p/6135576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!