Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
使用stl map的自动排序 代码也相当简洁 贴下代码#include<iostream> #include<string> #include<map> #include<vector> using namespace std; int main() { int m, n; cin >> n >> m; string str[100]; map<vector<int>, string>map2; for (int i = 0; i < m; i++) { cin >> str[i]; vector<int>vec; int count = 0; for (int j = 0; j < n; j++) { for (int k = j; k < n; k++) { if (str[i][j]>str[i][k]) count++; } } vec.push_back(count); vec.push_back(i); map2[vec] = str[i]; vec.clear(); } map<vector<int>, string>::iterator it; for (it = map2.begin(); it != map2.end(); it++) { cout << it->second << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator