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 |
这么 简单明了的代码为何总是 WA#include <iostream> #include <string> using namespace std; int calcInverseCount(string str) { int nums = 0; int temp[4] = {0}; for(int i=str.length()-1; i>=0; i--) { switch(str[i]) { case 'A': temp[1]++; //C temp[2]++; //G temp[3]++; //T break; case 'C': temp[2]++; temp[3]++; nums += temp[1]; break; case 'G': temp[3]++; nums += temp[2]; break; case 'T': nums += temp[3]; break; } } return nums; } int cmp(const void* a, const void* b) { return ( *(int*)a - *(int*)b); } int main() { int n, m; int i, j; cin >> n >> m; if(m <= 0 || n <= 0) return 0; string* arrayInput = new string[m]; // m strings new string[m] int* InverseNum = new int(m); for(i=0; i<m; i++) //nums of string { cin >> arrayInput[i]; //calculate inverse count InverseNum[i] = calcInverseCount(arrayInput[i]) * 1000 + i; } qsort(InverseNum, m, sizeof(int), cmp); for(i=0; i<m; i++) { cout << arrayInput[InverseNum[i] % 1000] << 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