题目链接:http://poj.org/problem?id=1007

本题属于字符串排序问题。思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体。最后把全部行按照这个总和从小到大排序即可。

 #include <iostream>
#include <algorithm>
using namespace std; struct DNA
{
char s[];
int count;
} d[]; int cmp(DNA a, DNA b)
{
return a.count < b.count; // 把全部DNA按照count从小到大排序
} int main()
{
int i, j, k, m, n, tot;
while (cin >> n >> m)
{
for (k = ; k < m; k++)
{
scanf("%s", d[k].s);
//cout << d[i].s << endl;
tot = ;
for (i = ; i < n; i++)
{
for (j = i+; j < n; j++) // 统计每行字母逆序的总数
{
if (d[k].s[i] > d[k].s[j])
tot++;
}
}
d[k].count = tot;
}
sort(d, d+m, cmp);
for (i = ; i < m; i++)
{
cout << d[i].s << endl;
}
}
return ;
}

poj 1007 DNA Sorting 解题报告的更多相关文章

  1. [POJ 1007] DNA Sorting C++解题

        DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 ...

  2. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  3. [POJ] #1007# DNA Sorting : 桶排序

    一. 题目 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95052   Accepted: 382 ...

  4. poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95437   Accepted: 38399 Des ...

  5. poj 1007 DNA sorting (qsort)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95209   Accepted: 38311 Des ...

  6. POJ 1007 DNA Sorting(sort函数的使用)

    Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

  7. POJ 1007 DNA sorting (关于字符串和排序的水题)

    #include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...

  8. Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)

     http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...

  9. POJ 3126 Prime Path 解题报告(BFS & 双向BFS)

    题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...

随机推荐

  1. python 学习5--matplotlib画图实践

    ### Python的强大很大一部分原因在于,它提供有很多已经写好的,可以现成用的对象 学习参考: http://www.cnblogs.com/vamei/archive/2013/01/30/28 ...

  2. 【BZOJ-2223】PATULJCI 可持久化线段树

    2223: [Coci 2009]PATULJCI Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 728  Solved: 292[Submit][S ...

  3. C#获取本机磁盘信息

    照着书敲的.留作笔记吧. using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...

  4. libcurl with telnet

    #include <stdio.h>#include <string.h>#include <curl/curl.h>#include <curl/easy. ...

  5. Linux内核之内存管理完全剖析

    linux虚拟内存管理功能 ? 大地址空间:? 进程保护:? 内存映射:? 公平的物理内存分配:? 共享虚拟内存.实现结构剖析   (1)内存映射模块(mmap):负责把磁盘文件的逻辑地址映射到虚拟地 ...

  6. 项目总结—jQuery EasyUI-DataGrid动态加载表头

    http://blog.csdn.net/zwk626542417/article/details/19248747 概要 在前面两篇文章中,我们已经介绍了在jQuery EasyUI-DataGri ...

  7. easyui datagrid使用

    http://www.cnblogs.com/zgqys1980/archive/2011/01/04/1925775.html 加载相关js和css,因为easyui依赖jquery,所有加载eas ...

  8. shared_ptr<> reset

    // std_tr1__memory__shared_ptr_reset.cpp // compile with: /EHsc #include <memory> #include < ...

  9. PRML Chapter 2. Probability Distributions

    PRML Chapter 2. Probability Distributions P68 conjugate priors In Bayesian probability theory, if th ...

  10. 如何使用网盘托管git项目

    话说近年来git已经成为项目源代码管理的标准工具,有不少免费托管网站可供使用,详情参考这篇文章: http://www.cnblogs.com/zdz8207/archive/2012/05/20/2 ...