Created
November 10, 2016 17:05
-
-
Save tamarous/791e5ba716bd96b590b7f0829a460a5b to your computer and use it in GitHub Desktop.
UVA 1368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int T,n,m; | |
#define maxn 1005 | |
#define maxm 52 | |
char DNA[maxm][maxn]; | |
char s[maxn]; | |
void processDNA() { | |
int count[maxn][4] = {0}; | |
for(int i = 0; i< m;i++) { | |
for(int j = 0;j < n;j++) { | |
if (DNA[i][j] == 'A') { | |
count[j][0]++; | |
} else if (DNA[i][j] == 'T') { | |
count[j][1]++; | |
} else if (DNA[i][j] == 'G') { | |
count[j][2]++; | |
} else { | |
count[j][3]++; | |
} | |
} | |
} | |
char x[4] = {'A','T','G','C'}; | |
for(int i = 0;i < n;i++) { | |
int max = -100; | |
int k = 0; | |
for(int j = 0;j < 4;j++) { | |
if (count[i][j] > max) { | |
max = count[i][j]; | |
k = j; | |
} | |
} | |
s[i] = x[k]; | |
} | |
s[n] = '\0'; | |
int dist = 0; | |
for(int i = 0;i < m;i++) { | |
for(int j = 0;j < n;j++) { | |
if (DNA[i][j] != s[j]) { | |
dist++; | |
} | |
} | |
} | |
printf("%s\n",s); | |
printf("%d\n",dist); | |
} | |
int main() | |
{ | |
scanf("%d",&T); | |
while (T--) { | |
scanf("%d %d",&m,&n); | |
for(int i = 0;i < m;i++) { | |
scanf("%s",DNA[i]); | |
} | |
processDNA(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment