#11212: NA(60%) 求救


who_am_I (kruztw)

學校 : 國立臺灣師範大學
編號 : 54056
來源 : [36.224.144.147]
最後登入時間 :
2023-04-22 22:46:31
d231. 97北縣賽-2-基因序列密碼問題 -- 97學年度北基區資訊學科能力競賽 | From: [114.26.12.80] | 發表日期 : 2016-07-27 20:47

#include<iostream>

using namespace std;

int main(){

char A[500], B[500];
int len, lenend, lent;
int i, j, k, it, jt, iin, jin;
bool in;

while(cin >> A >> B){
lent = 0; len = 0;

for(i = 0; A[i] != '\0'; i++);
for(j = 0; B[j] != '\0'; j++);
A[i] = 1, B[j] = 2;
in = false;
if(i >= j){
k = j;
for(j = 0; j<k && k - j > len; j++){
it = 0; jt = j;

while(it <= i && jt <= k){

if(B[jt] == A[it]){
if(!in)
iin = it;
lent++; jt++; in = true;}
else{
if(in){
lent > len ? len = lent, lenend = jt - 1, lent = 0: lent = 0;
in = false; jt = j; it = iin + 1;continue;}
}


it++;
}
}


if(!len)
cout << "E" << endl;
else{
for(i = lenend - len + 1; i <= lenend; i++)
cout << B[i];
cout << endl;}



}

else{
k = i;
for(i = 0; i<k && k - i > len; i++){
jt = 0; it = i;

while(jt <= j && it <= k){

if(A[it] == B[jt]){
if(!in)
jin = jt;
lent++; it++; in = true;}
else{
if(in){
lent > len ? len = lent, lenend = it - 1, lent = 0: lent = 0;
in = false; it = i; jt = jin + 1;continue;}

}
jt++;
}


}
if(!len)
cout << "E" << endl;
else{
for(i = lenend - len + 1; i <= lenend; i++)
cout << A[i];
cout << endl;}
}


}
}

 

 
ZeroJudge Forum