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++ WA了,g++ A了,郁闷……

Posted by blackRats at 2013-07-30 18:40:02 on Problem 1035
RT
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

char dic[10001][20];
int dicN;
int res[10001];
int ans;

bool change(char *a,char *b)
{
    int num=0;
    int len=strlen(a);
    for(int i=0;i<len;i++)
        if(a[i]!=b[i])
            num++;
    if(num==1)
        return true;
    else
        return false;
}

bool Add(char* word,char* dict)
{
	int dif=0;

	while(*dict)
	{
		if(*word != *dict)
		{
			dict++;
			dif++;
			if(dif>1)
				return false;
		}
		else
		{
			word++;
			dict++;
		}
	}
	return true;
}

int main()
{
    dicN=0;
    while(scanf("%s",dic[dicN]) && dic[dicN++][0]!='#');
    dicN--;

    char check[20];
    while(scanf("%s",check) && check[0]!='#')
    {
        ans=0;
        int len=strlen(check);

        bool correct=false;
        for(int i=0;i<dicN;i++)
        {
            int len2=strlen(dic[i]);
            if(len==len2)
            {
                if(strcmp(check,dic[i])==0)
                {
                    correct=true;
                    break;
                }
                if(change(dic[i],check))
                    res[ans++]=i;
            }
            else if(len2==len-1 && Add(dic[i],check))
                res[ans++]=i;
            else if(len2==len+1 && Add(check,dic[i]))
                res[ans++]=i;
        }

        if(correct)
        {
            printf("%s is correct\n");
            continue;
        }

        printf("%s:",check);
        for(int i=0;i<ans;i++)
            printf(" %s",dic[res[i]]);
        printf("\n");
    }
}

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