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

为什么wa

Posted by ljl08 at 2007-08-15 16:08:59 on Problem 3158
#include <iostream.h>
#include <string.h>
int cal(char *ms,char *ds){
	int a=strlen(ms);
	int b=strlen(ds);
	int i,j;
	int lenth=101;
	if(a>b){
		for(j=0;j<=a-b;j++){
			for(i=0;i<b;i++){
				if(int(ms[j+i]-'1')*int(ds[i]-'1'))break;
			}
			if(i==b)lenth=a;
		}
		for(i=b-2;i>=0;i--){
			for(j=0;j<=i;j++){
				if(int(ms[i-j]-'1')*int(ds[b-j-1]-'1'))break;
			}
			if(j==i+1)lenth=lenth>(a+b-i-1)?(a+b-i-1):lenth;
		}
		for(i=a-b+1;i<a;i++){
			for(j=0;j<a-i;j++){
				if(int(ms[i+j]-'1')*int(ds[j]-'1'))break;
			}
			if(j==a-i)lenth=lenth>(b+i)?(b+i):lenth;
		}
	}
	if(b>a){
		for(j=0;j<=b-a;j++){
			for(i=0;i<a;i++){
				if(int(ds[j+i]-'1')*int(ms[i]-'1'))break;
			}
			if(i==a)lenth=b;
		}
		for(i=a-2;i>=0;i--){
			for(j=0;j<=i;j++){
				if(int(ds[i-j]-'1')*int(ms[a-j-1]-'1'))break;
			}
			if(j==i+1)lenth=lenth>(a+b-i-1)?(a+b-i-1):lenth;
		}
		for(i=b-a+1;i<b;i++){
			for(j=0;j<b-i;j++){
				if(int(ds[i+j]-'1')*int(ms[j]-'1'))break;
			}
			if(j==b-i)lenth=lenth>(a+i)?(a+i):lenth;
		}
	}
	if(a==b){
		for(i=0;i<a;i++){
			if(int(ds[i]-'1')*int(ms[i]-'1'))break;
		}
		if(i==a)lenth = a;
		for(i=b-2;i>=0;i--){
			for(j=0;j<=i;j++){
				if(int(ms[i-j]-'1')*int(ds[b-j-1]-'1'))break;
			}
			if(j==i+1)lenth=lenth>(a+b-i-1)?(a+b-i-1):lenth;
		}
		for(i=1;i<a;i++){
			for(j=0;j<a-i;j++){
				if(int(ms[i+j]-'1')*int(ds[j]-'1'))break;
			}
			if(j==a-i)lenth=lenth>(b+i)?(b+i):lenth;
		}
	}
	lenth=lenth>(a+b)?(a+b):lenth;
	return lenth;
}
void main(){
	char ms[100],ds[100];
	cin.getline(ms,100);
	cin.getline(ds,100);
	cout<<cal(ms,ds)<<"\n";
}

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