Título: consulta ejercicio strings Publicado por: johnstafe en 9 Abril 2012, 02:27 am Hola tengo que resolver el siguiente ejercicio y probé de varias formas, pero no puedo encontrarle la vuelta.
Si alguien sabe como resolverlo, o tiene una idea de como pensarlo, agradezco su ayuda. Este es el link del ejercicio: http://uva.onlinejudge.org/external/4/450.html. Título: Re: consulta ejercicio strings Publicado por: MasterPM2 en 9 Abril 2012, 02:52 am a ver muestrame lo que llevas hasta el momento..
tambien estoy aprendiendo . Título: Re: consulta ejercicio strings Publicado por: johnstafe en 9 Abril 2012, 03:20 am probé de varias formas, pero las dos con las que mas intente son estas:
#include <iostream> #include <cstring> #include <set> #include <vector> #include <cstddef> #include <string> #include <iterator> using namespace std; unsigned int split(const std::string, std::vector<std::string>, char); int main(int argc, char *argv[]) { std::vector<std::string> v; int cant; cin >> cant; string depto; string persona; string pers[8]; set<vector> todos; for (int i=0;i<cant;i++){ cin >> depto; while (cin){ cin >> persona; unsigned int x = split( persona, v, ','); v.insert(depto); string aux = v.at(1); v.at(1) = v.at(3); v.at(3) = aux; todos.insert(v); } } set<vector>::iterator s1; s1 = todos.begin(); /* for(int i=0;i<todos.size;i++){ cout << "----------------------\n"; cout << todos.begin.at(0) << todo.begin.at(1) << todo.begin.at(2) << endl; cout << todos.begin.at(3) << endl; cout << "Department:" << todo.begin.at(7) << endl; cout << "Home Phone:" << todo.begin.at(4) << endl; cout << "Home Work:" << todo.begin.at(5) << endl; cout << "Campus Box:" << todo.begin.at(6) << endl; todo.begin.next; }*/ return 0; } unsigned int split(const std::string &txt, std::vector<std::string> &strs, char ch) { unsigned int pos = txt.find( ch ); unsigned int initialPos = 0; strs.clear(); // Decompose statement while( pos != std::string::npos ) { strs.push_back( txt.substr( initialPos, pos - initialPos + 1 ) ); initialPos = pos + 1; pos = txt.find( ch, initialPos ); } // Add the last one strs.push_back( txt.substr( initialPos, std::min( pos, txt.size() ) - initialPos + 1 ) ); return strs.size(); } Título: Re: consulta ejercicio strings Publicado por: johnstafe en 9 Abril 2012, 03:21 am esta es la otra forma:
#include <iostream> #include <cstring> #include <set> #include <vector> #include <cstddef> #include <string> using namespace std; int main(int argc, char *argv[]) { int cant; cin >> cant; string depto; size_t found; string linea; set<vector> todo; for(int i=0;i<cant;i++){ cin >> depto; while(!"\n\n"){ vector<string> datos; cin >> linea; for (j=0,j<7;j++){ found = linea.find(","); datos.push_back(linea.substr(0,found)); linea = linea.substr(found+1,linea.size()); } datos.insert(depto); todo.insert(datos); } } for(int i=0;i<todo.size;i++){ cout << "----------------------\n"; cout << todo.begin.at(0) << todo.begin.at(1) << todo.begin.at(2) << endl; cout << todo.begin.at(3) << endl; cout << "Department:" << todo.begin.at(7) << endl; cout << "Home Phone:" << todo.begin.at(4) << endl; cout << "Home Work:" << todo.begin.at(5) << endl; cout << "Campus Box:" << todo.begin.at(6) << endl; todo.begin.next; } return 0; } el tema es q no me las compila, ya que se traba el compilador, y no puedo saber en que le estoy errando Título: Re: consulta ejercicio strings Publicado por: flony en 14 Abril 2012, 00:02 am lastima que no se puede ver el ejercicio...
|