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

尼玛···为何不让用strrev啊~还好改改也过了~

Posted by quanyibo at 2014-04-21 22:29:15 on Problem 1226
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int nn;
        scanf("%d",&nn);
        int i,j,temp,minlen,k,ii,jj;
        char str[nn][102];

        scanf("%s",str[0]);
        minlen=strlen(str[0]);//假设最小长度为第一个输入的字符串
        for(i=1;i<nn;i++)          //找出最小长度字符串的长度
        {
            scanf("%s",str[i]);
             minlen=minlen<strlen(str[i])? minlen:strlen(str[i]);
        }
          char t[102];int Min=minlen;
         for(i=0;i<Min;i++) //将长途为minlen的子串取出
         {
             int sum;
             for(j=0;j<=strlen(str[0])-minlen;j++)//j为子串起点
             {
                 sum=0;
                 temp=0;
                 strncpy(t,&str[0][j],minlen);
                 t[minlen]='\0';
                 char tt[102];strcpy(tt,t);
                 tt[minlen]='\0';char flag;
                 for(ii=0;ii<strlen(t)/2;ii++)  //字符串翻转  要注意是一半!
                 {
                     flag=t[ii];
                     t[ii]=tt[strlen(t)-1-ii];
                     t[strlen(t)-1-ii]=flag;
                 }
                 //printf("%s  %s\n",t,tt);
                 for(k=1;k<nn;k++)
                 {
                     if(strstr(str[k],t)||strstr(str[k],tt))
                     sum++;
                     if(sum==nn-1)temp=1;
                     if(temp) goto z;
                 }
             }
             minlen-=1;
             if(minlen==0)goto z;
         }
         z:if(nn==1)
         {
             printf("%d\n",strlen(str[0]));
         }
         else
         printf("%d\n",minlen);
    }
    getchar();
    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