标签:
#include <iostream>#include <string>#include <algorithm>#include <queue>#define max_one 100#define max_two 50#define max_three 50using namespace std;struct node //structure must sign first{string str;int size;};struct cmp //return the most minimum string//pay attention ://must complete size first then complete string{bool operator() (const node &a, const node &b){if(a.size >b.size)return true;else if(a.size ==b.size)return a.str>b.str;else return false;}};priority_queue <node, vector<node>, cmp> que;void score_string(char *p, char *q, int two, int three) //score string into queue{string temp="";if(p>q){int length=three > p-q+two ? three : p-q+two;for(int i=0; i<length ;i++)temp+=*(q+i);node a;a.str=temp;a.size=length;que.push(a);}else if(p<q){int length=two > q-p+three ? two : q-p+three;for(int i=0; i<length ;i++)temp+=*(p+i);node a;a.str=temp;a.size=length;que.push(a);}else if(p=q) //pay attention : p=q such as this string//one :asdfgh two :asdfgh three:a;{int length=two >three ? two :three;for(int i=0; i<length ;i++)temp+=*(p+i);node a;a.str=temp;a.size=length;que.push(a);}}int main(){int T;cin>>T;while(T--){while(!que.empty() ) //each text must clean the queue{que.pop();}char one[max_one],two[max_two],three[max_three];cin>>one>>two>>three;int two_length=strlen(two); //score size of two three stringint three_length=strlen(three);char *p=strstr(one,two);char *q=strstr(one,three);if(p==NULL ||q==NULL)cout<<"No"<<endl;else{char *two_point[max_two]; //set pointer array score the possible way of stringchar *three_point[max_three];two_point[0]=p;three_point[0]=q;int size_two=1;char *temp_two=p,*temp_three=q;while( (temp_two=strstr(temp_two+1,two))!=NULL) //get different substring waytwo_point[size_two++]=temp_two;int size_three=1;while( (temp_three=strstr(temp_three+1,three))!=NULL)three_point[size_three++]=temp_three;for(int i=0; i<size_two; i++) //score{for(int j=0; j<size_three; j++)score_string(two_point[i], three_point[j], two_length, three_length);}cout<<que.top().str<<endl;}//cout<<que.top().str<<endl;}return 0;}
标签:
原文地址:http://www.cnblogs.com/sober-reflection/p/79c7d7830b0eb8580ab917fa8cdf1775.html