拆分·数字

Problem Description

Hdu Girls' Day is a traditional activityin Hdu. Girls in Hdu participate in the activity and show their talent andskill. The girls who win in the activity will become the Hdu's vividambassadors(形象大使). There aremany students in Hdu concern the activity. Now it's the finally competition todetermine who will be the Hdu's vivid ambassadors. The students vote for thegirl they prefer. The girl who has the most number of votes will be the first.You as a student representing Hdu Acm team has a chance to vote. Every girl whoparticipates in the activity has an unique No. and name. Because you very likeprime number, you will vote for the girl whose No. has the maximum number ofunique prime factors.

For example if the girl's No. is 12, and another girl's No. is 210, then youwill choose the girl with No. 210. Because 210 = 2 *3 * 5*7 , 12 = 2*2*3. 210have 4 unique prime factors but 12 just have 2. If there are many results, youwill choose the one whose name has minimum lexicographic order.

Input

The first line contain an integer T(1 <= T <= 100).Then T cases followed. Each case begins with an integer n(1 <= n <= 1000) which is the number of girls.And then followed n lines,each line contain a string and an integer No.(1 <= No. <= 2^31 - 1). Thestring is the girl's name and No. is the girl's No.The string's length will notlonger than 20.

Output

For each case,output the girl's namewho you will vote.

Sample Input

2
3
Kate 56
Lily 45
Amanda 8
4
Sara 55
Ella 42
Cristina 210
Cozzi 2

Sample Output

Kate
Cristina


用结构化数组来存下每个人的信息,并求出对应编号的不同因子的个数排序比较输出对应的名字

一、易错分析

1.考虑到编号最大为2^31- 1,所以求因子时应尽量缩短循环的次数防止超时

2.题目求的是不同因子的个数,所以相同的因子要跳过


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct S{
    char name[50];
    int num;
    int b;
};
S a[1010];
int fen(int m,int j)
{
    int k=0,i,flag=0;
    //a[j].b=0;
    for(i=2;i<=m;i++)
    {
        while(m%i==0)
        {
            if(i!=flag)
                a[j].b++;
            m/=i;
            flag=i;
        }
    }
}
int cmp(S c,S d)
{
    return strcmp(c.name,d.name)<0;
}
int main()
{
    int t,n,i,j;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%s %d",a[i].name,&a[i].num);
        sort(a,a+n,cmp);
        for(i=0;i<n;i++)
            fen(a[i].num,i);
//        for(i=0;i<n;i++)
//            printf("%s %d %d\n",a[i].name,a[i].num,a[i].b);
        int max=a[0].b;
        j=0;
        for(i=1;i<n;i++)
        {
            if(a[i].b>max)
            {
                j=i;
                max=a[i].b;
            }
        }
        printf("%s\n",a[j].name);
     }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值