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

ME TOO

Posted by 15331154 at 2016-07-03 17:59:23 on Problem 1007
In Reply To:自己测试对了但是提交是WA( `д′),求助 Posted by:zqu971223 at 2016-07-01 21:56:24
#include<iostream>
#include<map>
#include<string>
using namespace std;
int inversion(string str) {
	int count = 0;
	int len = str.length();
	for (int i = 0; i < len - 1; i++) {
		for (int j = i+1; j < len; j++) {
			if (str[i] > str[j]) count++;
		}
	}
	return count;
}

int main() {
	int m, n;
	cin >> m >> n;
	map<int, string> M;
	while (n--) {
		string str;
		cin >> str;
		M.insert(make_pair(inversion(str), str));
	}
	for (std::map<int, string>::iterator it = M.begin(); it != M.end(); it++) {
		cout << it->second << endl;
	}
	system("pause");
	return 0;
}

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