poj 1007 DNA Sorting 解题报告
题目链接: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 解题报告的更多相关文章
- [POJ 1007] DNA Sorting C++解题
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- [POJ] #1007# DNA Sorting : 桶排序
一. 题目 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95052 Accepted: 382 ...
- poj 1007 DNA Sorting
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 Des ...
- POJ 1007 DNA Sorting(sort函数的使用)
Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...
- POJ 1007 DNA sorting (关于字符串和排序的水题)
#include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3126 Prime Path 解题报告(BFS & 双向BFS)
题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...
随机推荐
- 【CodeForces 618B】Guess the Permutation
题 题意 有个1到n的一个全排列,告诉你第i个数和全部n个数相比的较小的是哪个,和自己相比时为0,于是有个主对角线为0的矩阵,求原数列 分析 我的想法是,给我们的每一行之和按大小排一下,就知道第i个数 ...
- POJ1364 King
Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...
- Spring监听器配置
使用spring框架时如果同时使用org.springframework.web.util.Log4jConfigListener监听器,那么在web.xml中的监听器的注册顺序为org.spring ...
- Latex 笔记
A source file is made up of text, formulas, and instructions (commands) to $\LaTeX.$ Commands start ...
- POJ2309BST(树状数组)
BST Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9182 Accepted: 5613 Description C ...
- poj1787Charlie's Change(多重背包+记录路径+好题)
Charlie's Change Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3720 Accepted: 1125 ...
- std::auto_ptr
auto_ptr是C++标准库中(<utility>)为了解决资源泄漏的问题提供的一个智能指针类模板(注意:这只是一种简单的智能指针) auto_ptr的实现原理其实就是RAII,在构造的 ...
- [LeetCode] Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- ajax 如何做到 SEO 友好
我猜你是在网络上搜索“ajax如何被搜索引擎收录”.“ajax SEO”.“ajax SEO友好”等关键词来到这里的.你可能已经很疲惫了,因为前段时间我也这样搜索,但是我发现搜索到的内容质量不高,有的 ...
- Jni中C++和Java的参数传递 参数对照
Jni中C++和Java的参数传递 如何使用JNI的一些基本方法和过程在网上多如牛毛,如果你对Jni不甚了解,不知道Jni是做什么的,如何建立一个基本的jni程序,或许可以参考下面下面这些文章:利用V ...