Пример #1
0
int main(void)
{
    char source[] = "abaaabbababbababbaabaababbababaabba";
    char target[] = "ababbaba";
    //char source[] = "abbaababab";
    //char target[] = "aba";

    int sLen = strlen(source);
    int tLen = strlen(target);
    int result[sLen];//出现最多次数为sLen个位置
    int i = 0;

    for(i = 0; i < sLen; i++)
    {
        result[i] = -1;
    }

    BruteForce(source,sLen,target,tLen,result);

    if(result[0] == -1)
    {
        printf("字符串%s中不含有字符串%s\n",source,target);
    }else
    {
        i = 0;
        do
        {
            printf("匹配成功,字符串%s在字符串中第%d次出现的位置为%d\n",target,i+1,result[i]);
        }while(result[++i] != -1);

    }

    return 0;
}
int main()
{
	char *string = "hereroheroero";
	char *pattern = "hero";
	BruteForce(pattern,strlen(pattern),string,strlen(string));
	printf("\n\n");
	return(0);
}
Пример #3
0
void DivideAndConquer(PointList* L,PointClosed* pointClosed,
                      int begin,int end)
{
    if(end - begin + 1 < 4)
    {
        BruteForce(L,pointClosed,begin,end);
    }
    else
    {
        int mid_point = (begin + end) / 2;
        double mid_index_x =L->list[mid_point].x;
        DivideAndConquer(L,pointClosed,begin,mid_point);
        DivideAndConquer(L,pointClosed,mid_point+1,end);
        Middle(L,pointClosed,mid_point,mid_index_x);
    }
}
Пример #4
0
int main()
{
    srand((unsigned)time(NULL));
    int N = 40000;
    int low = 0,high = N-1;
    PointList* L = newPointList(N);
    int i;
    for(i = 0; i < N; i++)
    {
        L->list[i].x = getRandomIndex(low,high)*67;
    }
    for(i = 0; i < N; i++)
    {
        L->list[i].x += getRandomIndex(low,high)*31;
    }
    for(i = 0; i < N; i++)
    {
        L->list[i].y = getRandomIndex(low,high)*73;
    }
    for(i = 0; i < N; i++)
    {
        L->list[i].y += getRandomIndex(low,high)*24;
    }
    //printPointList(L,N);
    printf("===============\n");
    quickSort(L,low,high);
    //printPointList(L,N);
    PointClosed pointClosed;
    pointClosed.space = 60000;
    BruteForce(L,&pointClosed,0,N-1);
    printf("最近点为:a:");
    printPoint(pointClosed.a);
    printf(" b:");
    printPoint(pointClosed.b);
    printf(" 距离:%lf\n",pointClosed.space);
    PointClosed pointClosed_2;
    pointClosed_2.space = 60000;
    DivideAndConquer(L,&pointClosed_2,low,high);
    printf("最近点为:a:");
    printPoint(pointClosed_2.a);
    printf(" b:");
    printPoint(pointClosed_2.b);
    printf(" 距离:%lf\n",pointClosed_2.space);
    return 0;
}
Пример #5
0
void Problem2::Run()
{
	std::cout << "Sum = " << BruteForce() << std::endl;
}
Пример #6
0
stat Stats::TestBloomFilter(string fname_){

    std::vector<string> urlsInList_ = BruteForce(fname_);
    std::vector<int> present_;   //indicate the relevant url is in the list or not(according to bloom filter)
    std::vector<int> inList_;    //indicate the relevant url is actually in the list or not

    std::ifstream ifp(fname_.c_str());
    string line;
    int urlcount_ = 0;

    if(!ifp.good()){
        cout<<"Can not open input data file"<<endl;
    }
    else{
        do{
            getline(ifp, line);
            if(line.size()<=f->urlLen_ && line.size()>=f->min_urlLen_ && line.size()>0)
                urlcount_++;
            Element * e = new Element(line);

            if(f->QueryElement(e))
                present_.push_back(1);
            else
                present_.push_back(0);

            bool x = false;
            for (int i = 0; i < urlsInList_.size(); ++i)
            {
                if(line == urlsInList_[i]){
                    x = true;
                    break;
                }
            }
            if(x)
                inList_.push_back(1);
            else
                inList_.push_back(0);

        }while(!ifp.eof());
    }
    ifp.close();

    double ffp_;
    double total_present = 0;
    double total_inlist = 0;
    for (int i = 0; i < present_.size(); ++i)
    {
        if(present_[i]==1)
            total_present++;
        if(inList_[i]==1)
            total_inlist++;
    }
    ffp_ = 1-(total_inlist/total_present);
    
    std::ofstream logfile("testresults.log",ios::app);
    logfile<<"Testing: ";
    logfile<<"out of "<<urlcount_<<";\n\n\ttotal present(according to BloomFilter): "<<total_present<<"\n\ttotal in list: "<<total_inlist<<"\n\tffp: "<<ffp_<<endl;
    logfile.close();
    
    stat a;

    a.present = total_present;
    a.inList = total_inlist;
    a.ffp = ffp_;
    a.urlcount = urlcount_;

    return a;
}
Пример #7
0
void MainWindow::processFile() {

    if (generalLock == false) {
        generalLock = true;
    } else {
        return;
    }

    QTime timer;

    if (!fileLoaded) {
        mainWindow.statusLabel->setText("No file loaded");
        return;
    } else {
        QString pattern = mainWindow.patternTextEdit->toPlainText();
        if (pattern == "") {
            mainWindow.statusLabel->setText("No pattern given");
        } else {
            QString output = "";
            QList<int> results;
            int elapsedTime;

            mainWindow.statusLabel->setText("Processing file contents...");
            QCoreApplication::processEvents();

            if (mainWindow.chooseAlgCombo->currentText() == "Brute Force") {
            	BruteForce bf= BruteForce();
                timer.start();
                results = bf.find(pattern, pattern.size(), textFileContents, textFileContents.size(), mainWindow.progressBar);
                elapsedTime = timer.elapsed();
            }
            else if (mainWindow.chooseAlgCombo->currentText() == "Morris-Pratt") {
                MorrisPratt mp = MorrisPratt();
                timer.start();
                results = mp.find(pattern, pattern.size(), textFileContents, textFileContents.size(), mainWindow.progressBar);
                elapsedTime = timer.elapsed();
            }
            else if (mainWindow.chooseAlgCombo->currentText() == "Boyer-Moore") {
            	BoyerMoore bm = BoyerMoore();
            	timer.start();
            	results = bm.find(pattern, pattern.size(), textFileContents, textFileContents.size(), mainWindow.progressBar);
            	elapsedTime = timer.elapsed();
            }
            else if (mainWindow.chooseAlgCombo->currentText() == "TwoWay") {
                TwoWay tw = TwoWay();
                timer.start();
                results = tw.find(pattern, pattern.size(), textFileContents, textFileContents.size(), mainWindow.progressBar);
                elapsedTime = timer.elapsed();
            }
            else {
                mainWindow.statusLabel->setText("Algorithm not supported");
                return;
            }



            mainWindow.statusLabel->setText("Preparing results...");
            QCoreApplication::processEvents();
            output = processOutput(results, elapsedTime);

            chartWidget->addResult(getNameShortcut(mainWindow.chooseAlgCombo->currentText()), "", pattern, elapsedTime, textFileContents.size() / 1024);
            chartWidget->repaint();

            mainWindow.statusLabel->setText("Processing finished");

            mainWindow.consoleBrowser->setText(output);
        }
    }
    generalLock = false;
}
Пример #8
0
void Problem3::Run()
{
	long prime = BruteForce(600851475143);

	std::cout << "Prime = " << prime << std::endl;
}