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 |
水题一道,0msAC,小规模数据排序还是用inset sort好,附代码。#include <stdio.h> char s[100][51] = {0}; int cnt[4] = {0}; int total = 0; int count[100] = {0}; int pos[100] = {0}; int main() { int n = 0, m = 0; int i = 0, j = 0, k = 0; scanf("%d %d", &n, &m); for(i = 0; i < m; i++) { scanf("%s", s[i]); } for(i = 0; i < m; i++) { for(j = 0; j < 4; j++) { cnt[j] = 0; } for(j = 0; j < n; j++) { switch(s[i][j]) { case 'A': { cnt[0]++; break; } case 'C': { cnt[1]++; break; } case 'G': { cnt[2]++; break; } case 'T': { cnt[3]++; break; } } } total = 0; for(j = 0; j < n; j++) { switch(s[i][j]) { case 'A': { cnt[0]--; break; } case 'C': { cnt[1]--; total += cnt[0]; break; } case 'G': { cnt[2]--; total += (cnt[0]+cnt[1]); break; } case 'T': { cnt[3]--; total += (cnt[0]+cnt[1]+cnt[2]); break; } } } count[i] = total; } for(i = 0; i < n; i++) { pos[i] = i; } for(i = 1; i < m; i++) { j = i; k = count[j]; while(k < count[j-1] && j > 0) { count[j] = count[j-1]; pos[j] = pos[j-1]; j--; } count[j] = k; pos[j] = i; } for(i = 0; i < m; i++) { printf("%s\n", s[pos[i]]); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator