pku1007 poj 1007 hdu1379 DNA Sorting

//poj1007
//puk 1007
//DNA Sorting
//开始时老是不能理解题意,后来仔细再看了一下题目和测试数据,恍然大悟啊
//题目给出若干个字符串,然后要你数出有多少对是前面一个比后面一个大的
//举个例子:A A C A T G A A G G,每一个数一数后面有多少个比它大
//分别是:  0 0 3 0 5 2 0 0 0 0  这一个串就有是10
//然后根据这个的大小给所有串排序
#include<iostream>
#include<string>
using namespace std;
struct DNA                         //结构体,方便排序
{
 string a;
 int length;
}dna[110];
int calNumber( string ch, int n )  //找出每一个串有多少对
{
 int count=0;
 int i,j;
 for( i=0; i<n-1; i++ )
  for( j=i+1; j<n; j++ )
  {
   if( ch[i]>ch[j] )
   {
    count++;
   }
  }
 return count;
}
int cmp( const void *a ,const void *b)   //qsort比较函数
{
             return (*(DNA *)a).length < (*(DNA *)b).length ? 1 : -1;
}
int main()
{
 int n,cases;
 int i;
 char a[100];
 scanf("%d%d",&n,&cases);
 for(i=0;i<cases;i++)
 {
  cin>>dna[i].a;
  dna[i].length=calNumber( dna[i].a , n );
//  cout<<dna[i].length<<endl;
 }
    qsort(dna,cases,sizeof(dna[0]),cmp);
// cout<<endl;
 for(i=cases-1;i>=0;i--)
  cout<<dna[i].a/*<<dna[i].length*/<<endl;
 return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值