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 |
求看问题在哪啊?一直WA#include <iostream> #include <string> using namespace std; int main(void){ string a,b,c; int len,i,j,k,tmp,n; bool flag=false; while(cin>>a&& a.compare("-1") ){ cin>>b; tmp=0; if(a.size()>b.size()){ flag=true; c=b; b=a; a=c; } for(i=0;i<=a.size()+b.size()-1;i++){ len = 0; if(i<a.size()){ for(j=0;j<=i;j++){ if(b[j]==a[a.size()-i+j-1]){ len++; } } }else if(i<b.size()){ for(j=0;j<a.size();j++){ if(a[j]==b[j+i-a.size()+1]){ len++; } } }else{ for(j=0;j<a.size()+b.size()-i-1;j++){ if(a[j]==b[i-a.size()+1]) len++; } } if(tmp<len){ tmp=len; } } if(flag){ c=b; b=a; a=c; } if(2*tmp==a.size()+b.size()){ cout<<"appx("<<a<<","<<b<<") = "<<1<<endl; }else if(tmp==0){ cout<<"appx("<<a<<","<<b<<") = "<<0<<endl; } else{ j= a.size()+b.size(); k=2*tmp; for(i=k;i>=2;i--){ if(k%i==0&& j%i==0){ k = k/i; j = j/i; } } cout<<"appx("<<a<<","<<b<<") = "<<k<<"/"<<j<<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