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

不知到哪里错了。。求看啊。

Posted by yj1111051021 at 2012-06-04 19:36:42 on Problem 1572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node
{
    char s1[50];
    char s2[50];
}rule[50];
int main()
{
    char str[500],str1[500],temp1[500],temp2[500];
    int i,j,k,n,len,leap;

    //freopen("in.txt","r",stdin);
    while(scanf("%d",&n)&&n)
    {
        getchar();
        for(i = 0;i < n;i++)
        {
            gets(rule[i].s1);
            gets(rule[i].s2);
        }
        gets(str);

        memset(str1,'\0',sizeof(str1));
        for(i = 0;i < n;i++)
        {

            memset(temp1,'\0',sizeof(temp1));
            memset(temp2,'\0',sizeof(temp2));

            len = strlen(rule[i].s1);
            for(j = 0;str[j] != '\0';j++)
            {
                leap = 0;
                for(k = 0;k < len && str[j+len] != '\0';k++)
                {
                    if(rule[i].s1[k] != str[j+k])
                    {
                        break;
                    }
                }
                if(k == len)
                leap = 1;
                if(leap)
                {
                    for(k = 0;k < j;k++)
                    temp1[k] = str[k];
                    temp1[k] = '\0';

                    strcat(temp1,rule[i].s2);
                    for(k = 0;str[j+len+k] != '\0';k++)
                    temp2[k] = str[j+len+k];
                    temp2[k] = '\0';

                    strcat(temp1,temp2);
                    strcpy(str,temp1);
                }

            }

        }

        puts(str);
    }

    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