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
|
//template <class Key, class T, class Compare = less<Key >,
//class Allocator = allocator < pair< const Key,T > > > class multimap;
// map<Key,T>::iterator it;
// (*it).first; // the key value (of type Key)
// (*it).second; // the mapped value (of type T)
// (*it); // the "element value" (of type pair<const Key,T>)
// it->first; // same as (*it).first (the key value)
// it->second; // same as (*it).second (the mapped value)
// Member types
// of template <class Key, class T, class Compare=less<Key>,
// class Allocator=allocator<pair <const Key, T> > > class map;
// key_type Key
// mapped_type T
// value_type pair<const Key,T>
// key_compare Compare
// value_compare Nested class to compare elements (see member function value_comp)
// allocator_type Allocator
// reference Allocator::reference
// const_reference Allocator::const_reference
// iterator Bidirectional iterator
// const_iterator Constant bidirectional iterator
// size_type Unsigned integral type (usually same as size_t)
// difference_type Signed integral type (usually same as ptrdiff_t)
// pointer Allocator::pointer
// const_pointer Allocator::const_pointer
// reverse_iterator reverse_iterator<iterator>
// const_reverse_iterator reverse_iterator<const_iterator>
#include<map>
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
using std::istringstream;
using std::ifstream;
using std::string;
using std::cout;
using std::cin;
using std::cerr;
using std::map;
using std::multimap;
char wordMatch_1 [20];
char wordMatch_2 [20];
char wordMatch_3 [20];
char wordMatch_4 [20];
char wordMatch_5 [20];
int relatedNUM_1;
int relatedNUM_2;
int relatedNUM_3;
int relatedNUM_4;
int relatedNUM_5;
int main()
{
multimap <string,int> words;
map <int,string> v_VALUE;
string str;
ifstream input("yes.txt");
if(input.fail())
{
cerr<<"\nThe file could not be opened.";
return -1;
}
int i=1;
while(getline(input,str))
{
istringstream in(str);
string s;
while(in>>s)
{
words.insert(make_pair(s,i));
}
v_VALUE.insert(make_pair(i,str));
i++;
}
string search;
cout<<"\nI hope this program to say * Please enter a sentence, we'll search each word:\n\n ";
cout<<"\nPlease enter (A) word for my weak program to search: ";
cin>>search;
cout<<"\nNUMBER OF MATCHES = " << words.count(search) <<'\n';
multimap<string,int>::iterator it1 = words.lower_bound(search);
multimap<string,int>::iterator it2 = words.upper_bound(search);
while(it1!=it2)
{
int x = it1->second;
map<int,string>::iterator iter = v_VALUE.find(x);
cout << '\n' << x << " ) " << iter->second << '\n';
it1++;
while(true)
{
// can do something else maybe here
// if(it1!=it2 && it1->second==x)
{
// ++it1;
// cout << "at the end" << '\n';
}
// else
{
break;
}
}
}
cout << "at the end" << '\n';
system("pause");
system ("CLS");
return main();
}
|