ZOJ Problem Set - 1188 DNA Sorting

来源:互联网 发布:linux创建文件目录 编辑:程序博客网 时间:2024/05/29 08:07
#include <iostream>#include <vector>#include <algorithm>using namespace std;bool comp (const string &s1, const string &s2);int main (){vector<string> vec;int block , n , m;string s;cin>>block;while (block--){cin>>n>>m;while (m--){cin>>s;vec.push_back(s);}sort(vec.begin() , vec.end() , comp);vector<string>::iterator it;for (it = vec.begin(); it != vec.end(); it++){cout<<*it<<endl;}/*for (int i = 0; i < vec.size(); i++) //用下标的方式输出,但是要注意使用vec.size(),否则会出现问题 {cout<<vec[i]<<endl;}*/if (block) cout<<endl;vec.clear();}return 0;}bool comp (const string &s1 , const string &s2){int c1 = 0 , c2 = 0;for (int i = 0; i < s1.size(); i++){for (int j = i + 1; j < s1.size(); j++){if (s1[i] > s1[j]) c1++;if (s2[i] > s2[j]) c2++;}}return c1<c2;}

0 0