ZOJ 1188 DNA Sorting
题目大意:给定一串字符串,查找字符串里字母逆序排列的对数,按照由少到多的顺序把所有字符串进行排列。
解法:用C++字符串string类的iterator,从每个字符串的起始开始,查找逆序字符的个数,然后用qsort方法按照reverseCount的大小快速排序。
参考代码:
#include<iostream>
#include<string>
#include<string.h>
#include<cstdlib>
#include<cstdio> using namespace std; struct DNAStr{
int index,reverseCount;
string str;
}DNA[102]; int countReverse(string s){
int num = 0;
string::iterator lit = s.begin();
string::iterator rit;
for(; lit < s.end(); lit++)
for(rit = lit + 1; rit <s.end(); rit++)
{
if(*lit > *rit)
{
num++;
}
}
return num;
}
int cmp(const void *a, const void *b){
DNAStr * x = (DNAStr *)a;
DNAStr * y = (DNAStr *)b; return (DNAStr *)x->reverseCount > (DNAStr *)y->reverseCount;
} int main(){
int cas,m,n; cin>>cas;
while(cas--){
getchar();
cin>>n>>m;
getchar();
for(int i=0;i<m;i++){
getline(cin,DNA[i].str);
DNA[i].index=i;
} for(int i=0;i<m;i++)
DNA[i].reverseCount = countReverse(DNA[i].str);
qsort(DNA,m,sizeof(DNAStr),cmp); for(int i=0;i<m;i++){
cout<<DNA[i].str<<endl;
}
if(cas)
cout<<endl; } return 0;
}
ZOJ 1188 DNA Sorting的更多相关文章
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- [POJ1007]DNA Sorting
[POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- poj 1007 (nyoj 160) DNA Sorting
点击打开链接 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 75164 Accepted: 30 ...
- [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 ...
- DNA Sorting(排序)
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- [POJ 1007] DNA Sorting C++解题
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 ...
随机推荐
- FR报表 自动缩小的代码
procedure TfrMemoView.Draw(Canvas: TCanvas); var newdx: Integer; OldScaleX, OldScaleY: Double; fs: i ...
- 【同行说技术】Python程序员小白变大神必读资料汇总( 三)
在文章<Python开发.调试.爬虫类工具大全>里面向大家总结了各种实用工具和爬虫技术,今天小编收集了5篇带有实例干货的资料,赶紧来看看吧!另外,喜欢写博客的博主可以申请加工程师博主交流群 ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- mysql中Access denied for user 'root'@'localhost' (using password:YES)(zhuan)
错误代码 1045Access denied for user 'root'@'localhost' (using password:YES) 如果你的mysql也出现以上这种提示, 建议你逐个字看完 ...
- DotNetBar v12.5.0.2 Fully Cracked
更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.5.0.2 如果遇到破解问题可以与我 ...
- putty基本操作
1,进入全屏 标题栏右键,菜单中就有full screen选项. 2,退出全屏 鼠标移到左上角,单击鼠标左键,就会跳出菜单,full screen勾去掉. 3,从putty中复制内容到剪切板 鼠标左键 ...
- 新版的tomcat里面get请求通过http协议的时候似乎默认是UTF-8的编码了吗?
不在servler.xml的connector中添加URICoding=“UTF-8”,使用默认值一样没有乱码,而添加URICoding=“iso-8859-1”就是乱码了. POST请求还是用iso ...
- <二叉树的基本操作(有层次遍历)>
#include<stdio.h> #include<stdlib.h> #include<string.h> #define num 100 #define OK ...
- (转)xcode5.0.2下国际化图文解说
原文:http://blog.csdn.net/dragoncheng/article/details/6703311 xcode5.0.2下国际化图文解说 分类: ...
- php大力力 [019节]php分页类的学习
2015-08-26 php大力力019.php分页类的学习 [2014]兄弟连高洛峰 PHP教程14.2.1 分页需求分析 14:18 [2014]兄弟连高洛峰 PHP教程14.2.2 分页类中分页 ...