hdu1379 DNA Sorting(字符串)

这个题是下午老师出的比赛题,看了很久都不知道这个题到底是什么意思,晚上上网看了下,才知道是求每个字符串里的每一个字母后面有几个比它小的字母的总和,并对总和按照从小到大排列,题目数据量较小,直接循环就过

《*——*》

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node
{
    int x,y;
}a[110];
int cmp(const void *a,const void *b)
{
    struct node *c,*d;
    c=(struct node *)a;
    d=(struct node *)b;
    if(c->y!=d->y)
    return c->x-d->x;
    else
        return c->y-d->y;
}
int main()
{
    int t,n,m;
    int i,j,k,num;
    char str[101][51];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(i=0;i<m;i++)
        {
            scanf("%s",str[i]);
            num=0;
            for(j=0;j<n;j++)
            {
                for(k=j+1;k<n;k++)
                {
                    if(str[i][j]>str[i][k])
                        num++;
                }
            }
            a[i].x=num;
            a[i].y=i;
        }
        qsort(a,m,sizeof(a[0]),cmp);

        for(i=0;i<m;i++)
        {
            printf("%s\n",str[a[i].y]);
        }

    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/zlyblog/p/3189835.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值