zoj3132(uva1368) DNA Consensus String(水)
2016-03-16 21:28
423 查看
水题,但感觉自己不在状态,可能是作业没做= =。没有初始化ans数组还WA了两次。。。
#include <stdio.h> #include <algorithm> #include <iostream> #include <queue> #include <cmath> #include <set> #include <vector> #include <string> #include <sstream> #include <ctype.h> #include <string.h> using namespace std; const int N = 1111; const int INF = 10000000; char Map[60] ; struct node { char c; int num; }tmp[4]; void init() { node tmp1, tmp2, tmp3, tmp4; tmp[0].c = 'A'; tmp[1].c = 'C'; tmp[2].c = 'G'; tmp[3].c = 'T'; for(int i = 0; i < 4; i ++) { tmp[i].num = 0; } } int main() { // freopen("in.txt", "r", stdin); int T, row, line; scanf("%d", &T); while(T --) { scanf("%d%d", &row, &line); memset(Map, 0, sizeof(Map)); for(int i = 0; i < row; i ++) scanf("%s", Map[i]); char ans ; memset(ans, 0, sizeof(ans)); for(int i = 0; i < line; i ++) { init(); for(int j = 0; j < row; j ++) { if(Map[j][i] == 'A') tmp[0].num ++; else if(Map[j][i] == 'C') tmp[1].num ++; else if(Map[j][i] == 'G') tmp[2].num ++; else if(Map[j][i] == 'T') tmp[3].num ++; } int maxx = -INF, ans0; for(int j = 0; j < 4; j ++) { maxx = max(maxx, tmp[j].num); } for(int j = 0; j < 4; j ++) { if(tmp[j].num == maxx) { ans[i] = tmp[j].c; break; } } } int num0 = 0; for(int i = 0; i < row; i ++) for(int j = 0; j < line; j ++) { if(Map[i][j] != ans[j]) num0 ++; } cout << ans << endl; printf("%d\n", num0); } return 0; }
相关文章推荐
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?