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了,自己排序一直超时,用qsort结构排序通过了#include "iostream" #include "string" #include "stdlib.h" #include "vector" using namespace std; class Astr{ public: string s; int a; }; int cmp(const void* x, const void* y){ return ((Astr*)x)->a > ((Astr*)y)->a?1:-1; } int main(){ int m_cases,n_len; vector<Astr> aver; string str; Astr as; cin>>n_len>>m_cases; for (int i=0; i<m_cases; i++) { cin>>str; aver.push_back(as); aver.at(i).s=str; } for (int j=0; j<m_cases; j++) { int inversion=0; for (int k=0; k<n_len-1; k++) { for (int l=k+1; l<n_len; l++) { if(aver.at(j).s.at(k)>aver.at(j).s.at(l)) inversion++; } } aver.at(j).a=inversion; } qsort(&aver[0], m_cases, sizeof(Astr), cmp); for (int haha=0; haha<m_cases; haha++) { cout<<aver.at(haha).s<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator