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

cpp真恶心。。

Posted by lql_accept at 2010-09-16 17:51:44 on Problem 3291
害的我换了好几个编译器。真郁闷。
#include <stdio.h>
#include <string.h>
using namespace std;
char a[200],b[200],ch;
int i,j,n,m,len,ans;
int f[200][200];
int main(){
    while((ch=getchar())!='0'){
        n=1; 
        a[n]=ch;
        while((ch=getchar())!='\n'){
            ++n;
            a[n]=ch;
        };
        m=0;
        while((ch=getchar())!='\n'){
            ++m;
            b[m]=ch;
        };
        memset(f,0,sizeof(f));
        for(i=1;i<=n;++i)
            for(j=1;j<=m;++j){
                f[i][j]=f[i-1][j]>f[i][j-1]?f[i-1][j]:f[i][j-1];
                if(a[i]==b[j]&&f[i][j]<f[i-1][j-1]+1) 
                    f[i][j]=f[i-1][j-1]+1;
            };
        len=f[n][m];            
        if(m<n){
            j=m;
            m=n;
            n=j;
        };
        len=n-len;
        ans=0;
        while(len>n-len||(n-len)*2<m){
            ++ans;
            n*=2;
        }    
        ++ans;
        printf("%d\n",ans);
    };    
    return 0;
}    

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