| ||||||||||
| 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 | |||||||||
Excited//In STL,sort could be customed,like this
#pragma region Head
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define null NULL
using namespace std;
#pragma endregion
int fun(const string &str)
{
int cnt = 0;
for (int i = 0; i < str.length(); ++i)
{
for (int j = i+1; j < str.length(); ++j)
{
if (str[i] > str[j])
{
cnt++;
}
}
}
return cnt;
}
bool cmp_byValue(pair<string, int>& p1, pair<string, int>& p2)
{
return p1.second < p2.second;
}
int main(void)
{
int x, y;
scanf("%d %d", &x, &y);
vector<pair<string, int>> vc;
for (int i = 0; i < y; ++i)
{
string str;
cin >> str;
vc.push_back(pair<string, int>(str, fun(str)));
}
sort(vc.begin(), vc.end(), cmp_byValue);
for (int i = 0; i < vc.size(); ++i)
{
cout << vc[i].first << endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator