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

C++

Posted by freelark at 2016-10-30 14:24:23 on Problem 1007
#include <iostream>
#include <stdlib.h>
#include <map>
#include <string>
using namespace std;
int inversions(const char* s);

int main(void)
{
	int col, row = 0;
	string line;
	multimap<int,string>tableDNA;
	cin >> col >> row;
	while (row--> 0){ 
		cin >> line;
		pair<int, string> p(inversions(line.c_str()), line);
		tableDNA.insert(p);
	}
	for (multimap<int, string>::iterator it = tableDNA.begin(); it != tableDNA.end(); it++){
		cout << it->second << endl;
	}
	system("pause");
	return 0;
}

int inversions(const char* s){
	int number = 0;
	for (int i = 0; i < strlen(s); i++){
		if (s[i] == 'A') continue;
		for (int j = i; j < strlen(s); j++){
			if (s[i]>s[j]) number++;
		}
	}
	return number;
}

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