| ||||||||||
| 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 | |||||||||
换了三个方法,用最简单的方法AC了,贴码让后来者参考一下#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct PAIR
{
string s;
long int count;
};
void sort_vector(vector<PAIR>&pp)
{
PAIR temp;
for(vector<PAIR>::size_type a=0;a!=pp.size();a++)
{
for(vector<PAIR>::size_type b=a+1;b!=pp.size();b++)
{
if(pp[a].count>pp[b].count)
{
temp=pp[a];
pp[a]=pp[b];
pp[b]=temp;
}
}
}
}
int main()
{
int n,m,i,k;
string str;
while(cin>>n>>m&&n<=50&&m<=100)
{
vector<PAIR> pair;
for(i=0;i!=m;i++)
{
cin>>str;
k=0;
for(string::size_type a=0;a!=n-1;a++)
{
for(string::size_type b=a+1;b!=n;b++)
{
if(str[a]>str[b])k++;
}
}
str[n]='\0';
PAIR p={str,k};
pair.push_back(p);
}
sort_vector(pair);
for(vector<PAIR>::size_type a=0;a!=pair.size();a++)
{
cout<<pair[a].s<<endl;
}
}
}
这里要注意的一个问题是:假如两个输入的字符串逆序数相同,就不改动它们的位置。之前用
map<int,string>的时候,就因为这个WA了.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator