Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪里错了呢?验证了很多数据都ok啊!!大侠们帮忙看下,谢了!!#include<iostream> #include<string> using namespace std; int main(void) { while(1) { char firstStr[501]; char secondStr[501]; cin>>firstStr; if(!strcmp(firstStr,"-1")) return 0; cin>>secondStr; int len1=strlen(firstStr); int len2=strlen(secondStr); if(strcmp(firstStr,secondStr)==0) { cout<<"appx("<<firstStr<<","<<secondStr<<") = "<<1<<endl; continue; } int sum=0; if(len1>len2) { for(int i=0;i<len1;i++) { int tmpsum=0; int tmp_i=i; for(int j=0;j<len2&&tmp_i<len1;j++,tmp_i++) { if(firstStr[tmp_i]==secondStr[j]) tmpsum++; } if(tmpsum>sum) sum=tmpsum; } } else { for(int i=0;i<len2;i++) { int tmpsum=0; int tmp_i=i; for(int j=0;j<len1&&tmp_i<len2;j++,tmp_i++) { if(firstStr[j]==secondStr[tmp_i]) tmpsum++; } if(tmpsum>sum) sum=tmpsum; } } int len=len1+len2; sum*=2; if(sum==0) { cout<<"appx("<<firstStr<<","<<secondStr<<") = "<<0<<endl; continue; } for(int i=2;i<=sum&&sum<=len;) { if(len%i==0&&sum%i==0) { len/=i; sum/=i; } else i++; } cout<<"appx("<<firstStr<<","<<secondStr<<") = "<<sum<<"/"<<len<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator