POJ 1007-DNA Sorting
来源:互联网 发布:g92车锥螺纹编程实例 编辑:程序博客网 时间:2024/06/05 16:48
题意
题目比较简单,就是求符串的逆序数,并从小到大输出,并且不改变相对顺序(相同逆序数的字符串位置不能改变)。
分析
可以利用STL中multimap的特性,代码如下:
Memory: 256K Time: 0MS Length:34LINES
#include<iostream>#include<map>#include<string>using namespace std;int calculate(const string & s){ int cnt = 0; for (int i = int(s.size() - 2); i >= 0; --i) for (string::size_type j = i; j != s.size() - 1; ++j) if (s[i] > s[j + 1]) ++cnt; return cnt;};int main(){ multimap<int, string> Mapping; int count = 0; int length = 0; cin >> length >> count; string DNA; while (count > 0) { cin >> DNA; Mapping.insert(make_pair(calculate(DNA), DNA)); --count; } multimap<int, string>::iterator iter = Mapping.begin(); while (iter != Mapping.end()) { cout << iter->second << endl; ++iter; } return 0;}
阅读全文
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
- linux知识点总结3
- XML解析出现An invalid XML character (Unicode: 0x**) was found in the comment.
- 重拾C语言-空指针
- Windows 常用软件备忘
- 每日vim系列0716
- POJ 1007-DNA Sorting
- 如何优雅的记录编程中遇到的问题
- Different types of SVM -- opencv
- 3278 & [kuangbin带你飞]专题一 简单搜索 C
- spring
- Scheduling Tasks定时任务
- POJ 1008--Maya Calendar
- 【面试题】C++综合面试题
- iOS中 new Date() 返回 NaN