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

新手,用c做的0.0

Posted by shixuan at 2020-06-06 09:32:23 on Problem 1035
#include <string.h>
#include <stdio.h>
char a[10000][20],b[10000][20];
int la,lb,l1,l2,book[10000];
void change(int x,int y)
{
	int i=0,j=0,cnt=0;
	while(i<l1&&j<l2)
	{
		if (b[x][i]==a[y][j])
		{
			i++;
			j++;
		}
		else
		{
			i++;
			j++;
			cnt++;
		}
		if (cnt>1)
			break;
	}

	if (cnt<=1)
		printf(" %s",a[y]);
}
void dele(int x,int y)
{
	int i=0,j=0,cnt=0;
	while(i<l1&&j<l2+1)
	{
		if (b[x][i]==a[y][j])
		{
			i++;
			j++;
		}
		else
		{
			i++;
			cnt++;
		}
		if (cnt>1)
			break;
	}
	if (cnt<=1)
		printf(" %s",a[y]);
}

void add(int x,int y)
{
	int i=0,j=0,cnt=0;
	while(i<l1+1&&j<l2)
	{
		if (b[x][i]==a[y][j])
		{
			i++;
			j++;
		}
		else
		{
			j++;
			cnt++;
		}
		if (cnt>1)
			break;
	}
	if (cnt<=1)
		printf(" %s",a[y]);
}

int main()
{

	la=lb=0;
	int i,j;
	while(~scanf("%s",a[la])&&a[la][0]!='#')
	{
		la++;
	}
	a[la][0]='\0';
	while(~scanf("%s",b[lb])&&b[lb][0]!='#')
	{
		lb++;
	}
	b[lb][0]='\0';

	int flag;
	for (i=0; i<lb; i++)
	{
		flag=0;
		for (j=0; j<la; j++)
		{
			if (!strcmp(b[i],a[j]))
			{
				flag=1;
				break;
			}
		}
		if (!flag)
			book[i]=1;
	}

	int f;
	for (i=0; i<lb; i++)
	{
		f=0;
		if (!book[i])
		{
			printf("%s is correct",b[i]);
		}
		else
		{
			printf("%s:",b[i]);
			for (j=0; j<la; j++)
			{
				l1=strlen(b[i]);
				l2=strlen(a[j]);
				if (l1==l2)
				{
					change(i,j);

				}
				else if (l1+1==l2)
				{
					add(i,j);
				}
				else if (l1==l2+1)
				{
					dele(i,j);
				}
			}
		}
		printf("\n");

	}
	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