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

总是Runtime Error,求指教!

Posted by 610832128 at 2014-07-26 16:52:38 on Problem 1035
#include <iostream>
#include <cstring>
#include <string>
#include <fstream>
#include <memory.h>
#include <cmath>
using namespace std;
int main()
{
    ifstream input;
    input.open("x.txt");
    string x[10001];
    string y[51];
    int i;
    int long_c[50];
    bool check[10000];
    int num_d = 0;
    int num_c = 0;
    int diff = 0;
    int k = 0;
    int h = 0;
    bool isFind = 0;
    while(1)
    {
        fflush(stdin);
        input >> x[num_d];
        if(x[num_d] != "#")
            num_d++;
        else
            break;

    }
    while(1)
    {
        fflush(stdin);
        input >> y[num_c];
        if(y[num_c] != "#")
            num_c++;
        else
            break;

    }
    input.close();

    for(i = 0;i < num_c;i++)
        long_c[i] = y[i].length();


    for(i = 0;i < num_c;i++)
    {
        memset(check,0,sizeof(check));
        isFind = 0;
        for(int j = 0;j < num_d;j++)
        {
            if(y[i] == x[j])
            {
                isFind = 1;
                y[i] += " is correct";
                break;
            }
            if(long_c[i] - x[j].length() == 1 || long_c[i] - x[j].length() == -1 || long_c[i] == x[j].length())
            {
                check[j] = 1;
            }

        }

        if(isFind == 1)
            continue;

        y[i] += ":";
        for(int j = 0;j < num_d;j++)
        {
            if(check[j] == 1)
            {
                diff = 0;
                if(long_c[i] == x[j].length())
                {
                    k = 0;
                    while(k < long_c[i])
                    {
                        if(y[i][k] != x[j][k])
                            diff++;
                        k++;
                    }
                }

                else if(long_c[i] - x[j].length() == 1)
                {
                    k = 0;
                    h = 0;
                    while(k < long_c[i])
                    {
                        if(h == x[j].length())
                            diff++;
                        else if(x[j][h] != y[i][k])
                        {
                            diff++;
                            k++;
                        }
                        else
                        {
                            h++;
                            k++;
                        }
                    }
                }

                else
                {
                    k = 0;
                    h = 0;
                    while(k < x[j].length())
                    {
                        if(h == long_c[i])
                            diff++;
                        else if(x[j][k] != y[i][h])
                        {
                            diff++;
                            k++;
                        }
                        else
                        {
                            h++;
                            k++;
                        }
                    }
                }
                if(diff == 1)
                {
                    y[i] += " ";
                    y[i] += x[j];
                }
            }
        }
    }

    ofstream output;
    output.open("y.txt");
    for(int i = 0;i < num_c;i++)
        output << y[i] << endl;
    output.close();

  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