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 20133820 at 2014-08-21 15:30:04 on Problem 3080
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int INF = 10000000;
char t[2000][70];

bool LCS(char t[], char a[]){
    for(int i = 0; i<60; i++){
        if(a[i] == t[0]){
            int k = 0, m = i;
            while(a[m] == t[k] && a[m] != '\0' && t[k] != '\0'){
                  m++;
                 k++;
            }
            if(k == strlen(t))
              return true;
        }
    }
    return false;
}

int main(){
   int T;
   scanf("%d",&T);
   while(T--){
       int m;
       scanf("%d",&m);

       char s[70];
       cin>>s;
       char a[15][70];
       for(int i = 1; i<m; i++)
            cin>>a[i];

       int k = 0;
       for(int i = 0; i<60; i++){
           for(int j = 1; j<=60-i; j++){
               strncpy(t[k],s+i,j);
               t[k++][j] = '\0';
           }
       }
       //cout<<t[59]<<endl;

       char ans[70];
       memset(ans, '\0', sizeof(ans));
       int ansl = 0;
       for(int i = 0; i<k; i++){
           int len = strlen(t[i]);
           bool flag = true;
           for(int j = 1; j<m; j++){
               if(!LCS(t[i],a[j]))
                   flag = false;
           }
           if(ansl < len && flag){
               strcpy(ans, t[i]);
               ansl = len;
           }
           if(ansl == len && flag){
              if(strcmp(ans, t[i]) > 0) strcpy(ans, t[i]);
           }
       }

       if(ansl<3) printf("no significant commonalities\n");
       else      printf("%s\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