Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<list>
- #include<fstream>
- #include<string>
- using namespace std;
- int obtenersumascii(string nombre) {
- int sumatoria = 0;
- for (int i = 0; i < nombre.size(); i++)
- {
- sumatoria += int(nombre.at(i));
- }
- return sumatoria;
- }
- void indexar(string archivo, vector<string> *nombrescarga) {
- string registro;
- ifstream arch(archivo);
- while (getline(arch, registro, '\r'))
- {
- nombrescarga->push_back(registro);
- }
- arch.close();
- }
- void main() {
- vector<string> *nombres = new vector<string>();
- indexar("CSV_Database_of_First_Names.csv", nombres);
- indexar("CSV_Database_of_Last_Names.csv", nombres);
- vector<list<string>*>arr;
- string aux;
- int espacios = 1000;
- for (int i = 0; i < espacios; i++)
- {
- arr.push_back(new list<string>());
- }
- for (int i = 0; i < nombres->size(); i++)
- {
- arr[obtenersumascii(nombres->at(i)) % espacios]->push_back(nombres->at(i));
- }
- for (int i = 0; i < espacios; i++)
- {
- if (arr[i]->size() != 0) {
- cout << "espacio " << i << ": ";
- for (list<string>::iterator it = arr[i]->begin(); it != arr[i]->end(); ++it) {
- cout << ' ' << *it;
- }
- cout << endl;
- }
- }
- string nombreabus;
- while (true)
- {
- cout << "Ingrese nombre a buscar: ";
- cin >> nombreabus;
- if (arr[obtenersumascii(nombreabus) % espacios]->size() != 0) {
- for (list<string>::iterator it = arr[(obtenersumascii(nombreabus) % espacios)]->begin(); it != arr[(obtenersumascii(nombreabus) % espacios)]->end(); ++it)
- if (*it == nombreabus) {
- cout << "espacio " << (obtenersumascii(nombreabus) % espacios) << ": ";
- cout << ' ' << *it;
- break;
- }
- cout << endl;
- }
- }
- cin.ignore(), cin.get();
- }
- //base de datos a descargar: https://www.sajari.com/resources/public-data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement