1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/*
* File: main.cpp
* Author: black4
*
* Created on January 13, 2012, 10:04 PM
*/
#include <map>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <cstring>
#include <sstream>
#include <vector>
#include <iomanip>
using namespace std;
int main ()
{
int o = system("lynx -dump \"http://www.haha.com\" > file.txt");
int number;
{
string data;
string text="file.txt";
int position=0;
ifstream getData (text.c_str());
if (getData.is_open())
{
while (getData.good())
{
string result;
while(getline(getData, result))
{data+=result;}
}
getData.close();
position=data.find("[101]")-0;
data.erase(data.begin(),data.begin()+position);
position=data.find("* [131]")+7;
data.erase(data.begin()+position,data.end());
ofstream output("file2.txt"); //create file for input
for(int n=104;n<132;n+=3)
{
stringstream intToString;
string name;
string date;
string price;
string line,tmp;
int newposition=0;
intToString<<n;
position=data.find("["+intToString.str()+"]");
line=data.substr(0,position);
newposition=line.find("in [");
name=line.substr(5,newposition-17);
date=line.substr(newposition-12,12);
cout<<name<<endl<<endl;
cout<<date<<endl<<endl;
int money;
money=line.find("S$");
price=line.substr(money,line.length());
cout<<price<<endl<<endl;
data.erase(data.begin(),data.begin()+position);
output << "[name]-[publish]-[pricing]"
<< '\n' << name<< "-" << date<< "-" << price <<'\n' << endl;
}
//advance searcher for file2.txt
multimap<string,int> words;
map<int,string> lines;
string str;
ifstream Myfile;
Myfile.open("file2.txt");
if(Myfile.fail())
{
cerr<<"\nThe file could not be opened.";
return -1;
}
int i=1;
while(getline(Myfile,str))
{
istringstream in(str);
string s;
while(in>>s)
{
words.insert(make_pair(s,i));
}
lines.insert(make_pair(i,str));
i++;
}
string search;
cout<<"\nEnter a word to search: ";
cin>>search;
cout<<"\nThe number of matches = "<<words.count(search)<<'\n';
multimap<string,int>::iterator it1=words.lower_bound(search);
multimap<string,int>::iterator it2=words.upper_bound(search);
{
int x=it1->second;
map<int,string>::iterator iter=lines.find(x);
cout<<'\n'<<x<<" ) "<<iter->second<<'\n';
it1++;
while(true)
{
if(it1!=it2 && it1->second==x)
{
it1++;
}
else
{
break;
}
}
}
cout<<'\n';
}
else
{
cout<<"Database not found.";
}
cin>>number;
}
return 0;
}
|