博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Blue Jeans(包含两个查找字符串的重要函数)
阅读量:5870 次
发布时间:2019-06-19

本文共 3735 字,大约阅读时间需要 12 分钟。

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

32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalitiesAGATACCATCATCAT该题注意除了按字符串长度排序,还有按字符串大小,找出字符串长度最大的来并且字符串最小的                                            (1)
#include
#include
using namespace std;string a[100];int main(){
int t,i,n,j,k;cin>>t; while(t--) {
cin>>n; int l=0; string b=""; for(i=0;i
>a[i]; for(i=a[0].length();i>=3;i--) {
for(j=0;j
// 当 str.find("哦")==string::npos时则说明字符串str中不存在“哦”这个字符,//反之,str.find("哦")!=string::npos则说明字符串str中存在“哦”这个字符
{
p
=
1
;
break
;
}
if
(p
==
0
&&(b
==
""
||b
>temp
))b
=temp
;
}
if
(b
!=
""
)
{
cout
<<b
<<endl
;l
=
1
;
break
;
}
}
if
(l
==
0
)
printf
(
"no significant commonalities
\n
"
);
}
return
0
;
}
 
 
/*substr(string,start,length)
string
必需。规定要返回其中一部分的字符串。//即字符串,当然表示类的函数时候参照上面;
start
必需。规定在字符串的何处开始。
正数 - 在字符串的指定位置开始 负数 - 在从字符串结尾的指定位置开始 0 - 在字符串中的第一个字符处开始
length
可选。规定要返回的字符串长度。默认是直到字符串的结尾。
正数 - 从 start 参数所在的位置返回 负数 - 从字符串末端返回
*/
echo substr("abcdef", 1, 3)//输出 "bcd"
[2]
echo substr("abcdef", -1); // 输出 "f"
echo substr("abcdef", -2); // 输出"ef"
echo substr("abcdef", -3, 1); // 输出"d"
echo substr("abcdef", 1, -1); //输出 "bcde"
(2)
#include
#include
using namespace std;string a[1000];int main(){
int t,i,n,j,k;cin>>t; while(t--) {
cin>>n; string b=""; for(i=0;i
>a[i]; for(i=0;i<=a[0].size();i++) {
for(j=0;j<=a[0].size();j++) {
bool p=0; string temp = a[0].substr(j, i); for(k=1;k
b.length())b=temp;else if(temp.length()==b.length()&&b>temp)b=temp; } }if(b.size()<3) printf("no significant commonalities\n"); else cout<
<
 

转载于:https://www.cnblogs.com/lengxia/p/4387833.html

你可能感兴趣的文章
LINUX初学之文本编辑器(vi ,vim)
查看>>
获取Android设备基本信息 TelephonyManager
查看>>
Fusion-io 和 VSAN 入门
查看>>
Ubuntu 时间同步配置备忘
查看>>
Oracle flashback闪回专题
查看>>
造轮子,为什么鄙视造轮子,我赞成造轮子!
查看>>
oracle报错pls-00103,在使用begin-end块的时候(动态SQL)
查看>>
Oracle chr() ascii()
查看>>
linux下tar.gz、tar、bz2、zip等解压缩、压缩命令
查看>>
VBS 调试
查看>>
4、设计模式循序渐进-结构型模式
查看>>
KDE 开发入门指导(KDE Development – A Beginner's Guide)
查看>>
欧洲新闻媒体与谷歌的冲突
查看>>
Android平台下使用Ksoap2调用传递复杂对象
查看>>
kindeditor 上传文件控件优化下。。
查看>>
一篇读懂深度学习中「训练」和「推断」的区别
查看>>
推论统计2-T测试
查看>>
只有程序员能看懂的西游记
查看>>
删除任何文件
查看>>
手机传感器
查看>>