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

stl c++ 900ms

Posted by STEVENCHEN123 at 2015-10-17 13:59:32 on Problem 1035
#include<iostream>
#include <sstream>
#include<string>
#include<cstdlib>
#include<cmath>
#include <queue>
#include<cstdio>
#include<cctype>
#include<stack>
#include<fstream>
#include<cassert>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<algorithm>
#include"limits.h"
using namespace std;
char list[15000][20];
int n=0;
char Dic[20][15000][20];
int sz[20]={0};
bool match(char* t,int l);
void lessMatch(char* t,int l);
void equalMatch(char* t,int l);
void moreMatch(char* t,int l);
bool mwd(char* mc,char* lc,int l);
std::map<string, int> m;
int seq[15000];
int ps=0;
int main()
{
#ifndef ONLINE_JUDGE
    std::ios::sync_with_stdio(0);
    freopen("/Users/steven/Desktop/tmp.txt","r",stdin);
    clock_t a=clock();
#endif
    char tmp[20];
    while(cin>>list[n++]&&strcmp(list[n-1], "#")!=0)
    {
        int len=strlen(list[n-1]);
        strcpy(Dic[len][sz[len]++], list[n-1]);
        m[list[n-1]]=n-1;
//        cout<<list[n-1]<<" "<<m[list[n-1]]<<endl;
        // cout<<tmp<<endl;
    }
    while(cin>>tmp&&strcmp(tmp, "#")!=0)
    {
        int l=strlen(tmp);
        if (match(tmp,l))
        {
            cout<<tmp<<" is correct\n";
        }
        else
        {
            ps=0;
            cout<<tmp<<":";
            lessMatch(tmp,l);
            equalMatch(tmp,l);
            moreMatch(tmp,l);
            sort(seq,seq+ps);
            for (int i = 0; i < ps; ++i)
            {
                cout<<" "<<list[seq[i]];
            }
            cout<<endl;
        }
    }
#ifndef ONLINE_JUDGE
    clock_t b=clock();
    cout<<"running time:"<<(b-a)/(double)CLOCKS_PER_SEC<<endl;
#endif
}
bool match(char* t,int l)
{
    for (int i = 0; i < sz[l]; ++i)
    {
        if (!strcmp(t, Dic[l][i]))
        {
            return true;
        }
    }
    return false;
}
void lessMatch(char* t,int l)
{
    for (int i = 0; i < sz[l-1]; ++i)
    {
        if (mwd(t,Dic[l-1][i],l))
        {
            // cout<<" "<<Dic[l-1][i];
            seq[ps++]=m[Dic[l-1][i]];
        }
    }
}
bool mwd(char* mc,char* lc,int l)
{
    for (int i = 0; i < l; ++i)
    {
        int ia=0,ib=0;
        bool flag=1;
        //        cout<<i<<" checked"<<endl;
        while(ib!=l-1)
        {
            if (ia==i)
            {
                ia++;
                continue;
            }
            if (mc[ia]!=lc[ib])
            {
                flag=0;
                break;
            }
            ib++;
            ia++;
        }
        if (flag)
        {
            return true;
        }
    }
    return false;
}
void equalMatch(char* t,int l)
{
    for (int i = 0; i < sz[l]; ++i)
    {
        for (int j = 0; j < l; ++j)
        {
            bool flag=1;
            for (int k = 0; k < l; ++k)
            {
                if (k==j)
                {
                    continue;
                }
                if (t[k]!=Dic[l][i][k])
                {
                    flag=0;
                    break;
                }
            }
            if (flag)
            {
                seq[ps++]=m[Dic[l][i]];
                break;
            }
        }
    }
}
void moreMatch(char* t,int l)
{
    for (int i = 0; i < sz[l+1]; ++i)
    {
        if (mwd(Dic[l+1][i], t, l+1))
        {
            seq[ps++]=m[Dic[l+1][i]];
            // cout<<" "<<Dic[l+1][i];
        }
    }
}


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