Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11542   Accepted: 4962

Description

The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated. 



As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with individual survey information to identify new genetic markers. 



A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be represented as TAGACC. 



Given a set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.

Input

Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:

  • A single positive integer m (2 <= m <= 10) indicating the number of base sequences in this dataset.
  • m lines each containing a single base sequence consisting of 60 bases.

Output

For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" instead. If multiple subsequences
of the same longest length exist, output only the subsequence that comes first in alphabetical order.

Sample Input

  1. 3
  2. 2
  3. GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
  4. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  5. 3
  6. GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
  7. GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
  8. GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
  9. 3
  10. CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  11. ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  12. AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

  1. no significant commonalities
  2. AGATAC
  3. CATCATCAT

Source

解题报告
真心不想写这解题报告。。。
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. char str[12][100],ch[100],ans[100];
  7. int main()
  8. {
  9. int t,i,j,k,n,maxl,f;
  10. cin>>t;
  11. while(t--)
  12. {
  13. memset(str,0,sizeof(str));
  14. memset(ans,0,sizeof(ans));
  15. cin>>n;
  16. maxl=0,f=0;
  17. for(i=0; i<n; i++)
  18. cin>>str[i];
  19. for(i=0; i<58; i++)
  20. {
  21. for(j=3; j<=60-i; j++)
  22. {
  23. strncpy(ch,str[0]+i,j);
  24. ch[j]=0;
  25. f=0;
  26. for(k=1; k<n; k++)
  27. {
  28. if(strstr(str[k],ch)==NULL)
  29. {
  30. f=1;
  31. break;
  32. }
  33. }
  34. if(!f)
  35. {
  36. if(j>maxl)
  37. {
  38. maxl=j;
  39. strcpy(ans,ch);
  40. }
  41. else if(j==maxl)
  42. {
  43. if(strcmp(ch,ans)<0)
  44. strcpy(ans,ch);
  45. }
  46. }
  47. }
  48. }
  49. if(maxl)
  50. cout<<ans<<endl;
  51. else cout<<"no significant commonalities"<<endl;
  52. }
  53. return 0;
  54. }

POJ训练计划3080_Blue Jeans(串处理/暴力)的更多相关文章

  1. POJ训练计划1035_Spell checker(串处理/暴力)

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18418   Accepted: 6759 De ...

  2. POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)

    <题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1.  最长公共串长度小于3输出   no significant co ...

  3. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  4. POJ 3080 Blue Jeans(串)

    题目网址:http://poj.org/problem?id=3080 思路: 以第一个DNA序列s为参考序列,开始做以下的操作. 1.将一个字母s[i]作为匹配串.(i为当前遍历到的下标) 2.遍历 ...

  5. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  6. POJ训练计划

    POJ训练计划 Step1-500题 UVaOJ+算法竞赛入门经典+挑战编程+USACO 请见:http://acm.sdut.edu.cn/bbs/read.php?tid=5321 一.POJ训练 ...

  7. POJ 3294 n个串中至少一半的串共享的最长公共子串

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12484   Accepted: 3502 Descr ...

  8. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

  9. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

随机推荐

  1. linux命令:使用man, 导出man

    要查一个命令怎么使用,使用"man 命令", eg: man find, man ls; "info 命令"貌似也可以看, info find, info ls ...

  2. 关于android的nfc问题

    最近在研究android的nfc问题 首先再网上有很多关于android nfc 读写的问题,但是大多数都是关于Mifare Classic类型卡的读写,我百试不得骑解,于是自己写了一些程序供大家参考 ...

  3. 也谈基于NodeJS的全栈式开发(基于NodeJS的前后端分离)

    前言 为了解决传统Web开发模式带来的各种问题,我们进行了许多尝试,但由于前/后端的物理鸿沟,尝试的方案都大同小异.痛定思痛,今天我们重新思考了“前后端”的定义,引入前端同学都熟悉的NodeJS,试图 ...

  4. javascript 判断IOS版本号

    先来观察 iOS 的 User-Agent 串: iPhone 4.3.2 系统: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; ...

  5. Android ListView 之 SimpleAdapter 二 (包含 item 中按钮监听)

    1    MainActivity.java package com.myadapter; import java.util.ArrayList; import java.util.HashMap; ...

  6. Oracle 经常使用的改动语句

    一.表Table 測试表:MY_TEST_TABLE -- Create table create table MY_TEST_TABLE ( A VARCHAR2(30), B NUMBER(10) ...

  7. ArcGIS制图——多图层道路压盖处理

    [1]      启动ArcMap,载入各道路要素类.生成名为All-Roads的图层组,如他所看到的,符号级别绘制将对图层组内图层符号起作用: 图层组设置符号等级 [2]      在内容列表中,右 ...

  8. uva 10951 - Polynomial GCD(欧几里得)

    题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...

  9. [置顶] PMBOOK第四版-ITO与数据流图总结

    具体文档下载地址: 点击打开文档下载地址 :http://download.csdn.net/detail/lyjluandy/6694205 一.过程组与知识领域表(简图) 二.输入 - 工具 - ...

  10. 3篇OAuth的文章

    http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html http://blog.unvs.cn/archives/oauth-qq1.0-devel ...