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 |
搞不懂为什么要改成51改成51之前都是“Output Limit Exceeded”,改成51就AC了。 #include <iostream> #include <algorithm> #include <vector> using namespace std; typedef pair<char*,int> node; typedef unsigned int UINT; inline UINT cacu(const char str[],int len) { UINT sum = 0; for(int i = 0; i < len - 1; ++i) for(int j = i + 1; j < len; ++j) { if( str[i] > str[j]) sum++; } return sum; } bool measure_compare(const node &a,const node &b) { return a.second < b.second; } int main(int argc, char *argv[]) { int n,m; UINT sum; char str[100][51] = {0}; //题目明明说最大为50 vector<node>vec_str; cin>>n>>m; for(int i = 0;i < m; ++i) { cin>>str[i]; sum = cacu(str[i],n); vec_str.push_back( make_pair(str[i],sum) ); } stable_sort(vec_str.begin(),vec_str.end(), measure_compare); for(int i = 0; i < vec_str.size(); ++i) { cout<<vec_str[i].first<<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