Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Excited

Posted by int64_t at 2018-04-15 10:11:46 on Problem 1007
//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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator