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 |
Re:第一次发代码,很挫,大家见谅!已经AC了哦In Reply To:第一次发代码,很挫,大家见谅!已经AC了哦 Posted by:xiaodaodao at 2013-03-27 10:28:43 #include <stdio.h> #include <string.h> #include <stdlib.h> int inversion(char *s) { int retval = 0; int a = 0, c = 0, g = 0; for (int i = strlen(s) - 1; i >= 0; i--) { switch (s[i]) { case 'T': retval += g; case 'G': retval += c; if (s[i] == 'G') g++; case 'C': retval += a; if (s[i] == 'C') c++; case 'A': if (s[i] == 'A') a++; break; } } return retval; } int compare(const void *a, const void *b) { return inversion((char *)a) - inversion((char *)b); } int main() { // FILE *fin = fopen("p1007.in", "r"); char s[120][120]; int n, m; scanf( "%d %d\n", &n, &m); for (int i = 0; i < m; i++) scanf( "%s\n", s[i]); qsort(s, m, sizeof(s[0]), compare); for (int i = 0; i < m; ++i) printf("%s\n", s[i]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator