offline
- Neshone88
- Novi MyCity građanin
- Pridružio: 08 Jul 2011
- Poruke: 1
|
Ljudi imam sad ovaj problem. Treba da iz odredjenog text fajla na osnovu unetog broja iz tog reda ispise neki broj u tom redu koji je uvek na istom mestu.
U Text fajlu imam sledeci text:
- insert into deonica (iddeonica,duzina,Vn,tip_voda,presek,Rd,Ri,Ro,Xd,Xi,Xo,Bd,Bi,Bo,Gd,Gi,Go,pocetak,kraj)
- values (4001,1,20,2,null,0.209,0.209,0.75,0.117,0.117,0.112,0.116,0.116,0.695,0,0,0,2001,5001)
- insert into deonica (iddeonica,duzina,Vn,tip_voda,presek,Rd,Ri,Ro,Xd,Xi,Xo,Bd,Bi,Bo,Gd,Gi,Go,pocetak,kraj)
- values (4002,2,20,2,null,0.209,0.209,0.75,0.117,0.117,0.112,0.116,0.116,0.695,0,0,0,5001,5002)
- insert into deonica (iddeonica,duzina,Vn,tip_voda,presek,Rd,Ri,Ro,Xd,Xi,Xo,Bd,Bi,Bo,Gd,Gi,Go,pocetak,kraj)
- values (4003,2.5,20,2,null,0.209,0.209,0.75,0.117,0.117,0.112,0.116,0.116,0.695,0,0,0,5002,5007)
Ja na osnovu unete deonice koja ima iddeonica=4001 (znaci unosom broja 4001) treba da ispisem pocetak koji ima vrednost u redu 2001.
Uz pomoc drugara sam uspeo da odradim sledeci kod, mislio sam da znam c++ dok nisam poceo da se bavim malo. Ovde pojedine naredbe ni ne razumem :/
- #include <iostream>
- #include <fstream>
- #include <map>
- #include <sstream>
-
- int main(int argc, char* argv[]) {
- if (argc != 2) {
- std::cerr << "Usage: test [inputfile]" << std::endl;
- return 1;
- }
- std::fstream stream(argv[1]);
- if (!stream.good()) {
- std::cerr << "Error: could not open file: " << argv[1] << std::endl;
- return 2;
- }
- std::string line;
- std::map<int, std::string> map;
- while (std::getline(stream, line)) {
- std::string::size_type pos = line.find(',');
- std::stringstream sstream(line.substr(0, pos));
- int index;
- sstream >> index;
- map[index] = line.substr(pos+2);
- }
- int in;
- while (std::cin >> in) {
- std::map<int, std::string>::iterator i = map.find(in);
- if (i == map.end())
- std::cerr << "index not found" << std::endl;
- else
- std::cout << i->second << std::endl;
- }
- return 0;
- }
|