POJ 1007 DNA Sorting
来源:互联网 发布:java 暂停1秒 编辑:程序博客网 时间:2024/06/05 14:54
用STL封装的排序算法和自定义排序规则来进行字符串排序。
// codingEx.cpp : Defines the entry point for the console application.
// author : momogary1204//#include "stdafx.h"
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int sortStepLen(const string& input);
bool less_second(const pair<int, int>& m1, const pair<int, int>& m2){
return m1.second < m2.second;
}
const int MAX_LEN = 50;
const int MAX_CASE = 100;
int main()
{
int strLen = 0, strNum = 0;
cin >> strLen >> strNum;
string array[MAX_CASE];
//int sortDist[MAX_CASE];
vector<pair<int, int>> tmp;//pair对实现字符串和其乱序个数对应
for (int i = 0; i<strNum; i++){
cin >> array[i];
tmp.push_back(pair<int, int>(i, sortStepLen(array[i])));
//cout << sortDist[i] << ' ';
}
//STL封装的排序函数,第三个参数系统有自己的less仿函数,注意自定义比较函数的命名,前两个参数是范围的随机访问迭代器
sort(tmp.begin(), tmp.end(), less_second);
for (int i = 0; i < strNum; i++){
cout << array[tmp[i].first] << endl;
}
return 0;
}
//计算乱序对的个数
int sortStepLen(const string& input){
int len = input.length();
int stepLen = 0;
for (int i = 0; i<len; i++){
for (int j = i + 1; j<len; j++){
if (input[i]>input[j]){
stepLen += 1;
}
}
}
return stepLen;
}
0 0
- POJ 1007 DNA Sorting
- poj 1007 DNA Sorting
- POJ 1007 DNA Sorting
- POJ-1007 DNA Sorting
- 【POJ】1007 DNA Sorting
- POJ-1007:DNA Sorting
- poj 1007 DNA Sorting
- POJ 1007 DNA Sorting
- POJ 1007 DNA Sorting
- poj 1007 DNA Sorting
- POJ 1007 DNA Sorting
- 【POJ】1007 DNA Sorting
- poj 1007 DNA sorting
- POJ 1007 DNA Sorting
- poj 1007 DNA Sorting
- [POJ][1007]DNA Sorting
- POJ 1007 DNA Sorting
- poj 1007 DNA sorting
- Java泛型详解
- wireshark cannot find interface
- Win32 API 心得
- Linux多线程信号量的概念和使用
- SSH 框架搭建与开发
- POJ 1007 DNA Sorting
- python脚本使用SFTP下载远程计算机文件
- 随机数的使用
- C++从Txt中读取内容
- git之Pushing to the remote branch is not fast-forward错误解决
- Android 工具类 —— 判断网络连接状态、GPS是否打开、基站信息和手机IMSI码
- ios9设置bitcode AMR编译
- 计算机视觉中的曲率尺度空间技术
- 屏幕旋转方向