Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大虾做出来可以教教我吗?我憋好久憋出来一个超时。。。

Posted by nabice at 2010-01-29 21:20:35 on Problem 1934
我的邮箱是nabice@163.com   谢谢。。。。。。。。

#include<iostream>
#include<string>
using namespace std;
int len_a,len_b,n,len;
char rst[10000][81];
char result[1000][81];
string a,b;
string c(81,'\0');
void strcpy(char *to,const char *from){
	for(;(*to=*from)!='\0';++from,++to);
}
int strcmp(char *a,char *b){
	int result;
	while(1){
		if((result=*a-*b)!=0)
			break;
		a++;b++;
		if(!*a)
			break;
	}
	return result;
}
void sort(){
	int j=0;
	int i=0;
	int j_temp;
	int flag;
	strcpy(result[j],rst[i]);
	for(int i=1;i<n;i++){
		j_temp = j;
		flag = strcmp(result[j],rst[i]);
		while((j_temp>=0)&&(flag>0)){
			strcpy(result[j_temp+1],result[j_temp]);
			j_temp--;
			flag = strcmp(result[j_temp],rst[i]);
		}
		if(flag){
			strcpy(result[j_temp+1],rst[i]);
			j++;
		}
	}
	n = j + 1;
}
int find_b(int i,int j,int k){
	int flag = 0;
	int temp_a,temp_b;
	for(int temp=j;temp<len_b;temp++){
		if(a[i]==b[temp]){
			flag = 1;
			j = temp + 1;
			break;
		}
	}
	if(flag&&i+1<len_a){
		c[k]=a[i];
		k++;
		for(int temp=i+1;temp<len_a;temp++){
			temp_a = find_b(temp,j,k);
			temp_b = (temp_b>temp_a)?temp_b:temp_a;
		}
		return temp_b;
	}else{ 
		if(flag){
		c[k] = a[i];
		k++;
	}
		c[k] = '\0';
		if(k>len){
			len = k;
			n = 0;
			c.copy(rst[n++],k+1);
		}else if(k == len){
			c.copy(rst[n++],k+1);
		}
		return k;
	}
}
int main(){
	while(true){
		n=0;
		len=0;
		a=b="";
		cin >> a >> b;
		len_a = a.length();
		len_b = b.length();
		if(!len_a||!len_b) break;
		for(int temp=0;temp<len_a;temp++){
			find_b(temp,0,0);
		}
		sort();
		for(int i=0;i<n&&i<1000;i++)
			cout << result[i] <<endl;
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator