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 "stdafx.h" #include <algorithm> #include <iostream> using namespace std; int CalMeasure(char *ch, int m); struct DNA { char *ch; int num; }; bool compare(DNA a, DNA b) { if(a.num<b.num) return 1; else return 0; } int main() { int m,n; cin>>m>>n; int i,j; DNA *DNAList=new DNA[n]; for(i=0;i<n;i++) { cin.clear(); cin.sync(); DNAList[i].ch=new char[m]; cin.getline(DNAList[i].ch,m+1,'\n'); DNAList[i].num=CalMeasure(DNAList[i].ch, m); } stable_sort(DNAList,DNAList+n,compare); for(i=0;i<n;i++) { cout<<DNAList[i].ch<<endl; } return 0; } int CalMeasure(char *ch, int m) { if(m==1) return 0; int sum=0; int i; int j; for(i=0;i<m-1;i++) { for(j=i+1;j<m;j++) { if(ch[i]>ch[j]) { sum++; } } } return sum; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator