Advertisement
encoree1996

bogactwo czesc glowna

May 18th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <fstream>
  7. #include <sstream>
  8. #define _VEC(name,type,array) vector<type> name(array,array+sizeof(array)/sizeof(array[0]))
  9. #define _foreach(var,container) for(unsigned var=0;var<container.size();var++)
  10. #define _SEP "*x*x*x*"
  11. #define _RT return true
  12. #define _V void
  13. #define _X bool
  14. #define __ sort
  15. #define _x_ getline
  16. #define lel break
  17. #define fag while
  18. #define nn left
  19. #define rn right
  20. #define _for case
  21. using namespace std;int ID = 0;class _BF{public:string _x_D, _0x1337, _n00b, ___, _encore,_0x0;int _ID;
  22. _BF(){_x_D=_0x1337=_n00b=___=_encore=_0x0=" ";_ID = ID++;}_V nul(){_x_D=_0x1337=_n00b=___=_encore=_0x0="";}};
  23. static const string __cmd[] = {"/help","/edit","/add","/sort","/exit","/dump","/load","/print"};
  24. _VEC(_cmd,string,__cmd);vector<_BF> _db;_V parseInput(string &);_V _w(string);_V _ex();_V help();
  25. _V add();_V _sort();_V print();_V edit();_V _dm();_V load();_V find();_X _tCM(_BF,_BF);_X _tCMo(_BF,_BF);_X _tCD(_BF,_BF);_X _tCW(_BF,_BF);_X _tCK(_BF,_BF);_X _tCKo(_BF,_BF);_X _iC(_BF,_BF);int main(){help();string n;for(;;){_x_(cin,n);
  26. parseInput(n);if(n=="/_ex")lel;_w("");}return 0;}_V _w(string in){cout<<"> "<<in;}_V help(){__(_cmd.begin(),_cmd.end());_w("Dostepne komendy: \n");_w("");_foreach(i,_cmd)
  27. cout<<_cmd[i]<<" ";cout<<endl;_w("");}_V add(){string in="";char choice;_BF bf;
  28. _w("\x50\x6f\x64\x61\x6a\x20\x6d\x61\x72\x6b\x65\x20\x73\x61\x6d\x6f\x63\x68\x6f\x64\x75\x3a\x20");_x_(cin,in);bf._x_D = in;
  29. _w("\x50\x6f\x64\x61\x6a\x20\x6d\x6f\x64\x65\x6c\x20\x73\x61\x6d\x6f\x63\x68\x6f\x64\x75\x3a\x20");_x_(cin,in);bf._0x1337 = in;
  30. _w("\x50\x6f\x64\x61\x6a\x20\x77\x6c\x61\x73\x63\x69\x63\x69\x65\x6c\x61\x3a\x20");_x_(cin,in);bf._n00b = in;
  31. _w("\x50\x6f\x64\x61\x6a\x20\x64\x61\x74\x65\x20\x6b\x72\x61\x64\x7a\x69\x65\x7a\x79\x3a\x20");_x_(cin,in);bf.___ = in;
  32. _w("\x50\x6f\x64\x61\x6a\x20\x6b\x6f\x6e\x74\x61\x6b\x74\x20\x64\x6f\x20\x77\x6c\x61\x73\x63\x69\x63\x69\x65\x6c\x61\x3a\x20");_x_(cin,in);bf._encore = in;
  33. _w("\x44\x6f\x64\x61\x74\x6b\x6f\x77\x65\x20\x6b\x6f\x6d\x65\x6e\x74\x61\x72\x7a\x65\x3a\x20");_x_(cin,in);bf._0x0 = in;_db.push_back(bf);
  34. _w("\x52\x65\x6b\x6f\x72\x64\x20\x70\x6f\x6d\x79\x73\x6c\x6e\x69\x65\x20\x64\x6f\x64\x61\x6e\x79\x20\x64\x6f\x20\x62\x61\x7a\x79\x20\x64\x61\x6e\x79\x63\x68\x2e\n");}_V _sort(){_w("\x57\x65\x64\x6c\x75\x67\x20\x6b\x74\x6f\x72\x65\x6a\x20\x74\x61\x62\x65\x6c\x69\x20\x63\x68\x63\x65\x73\x7a\x20\x70\x6f\x73\x6f\x72\x74\x6f\x77\x61\x63\x20\x62\x61\x7a\x65\x20\x64\x61\x6e\x79\x63\x68\x3f\n");
  35. _w("\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\n");
  36. _w("\x7c\x20\x4d\x61\x72\x6b\x61\x20\x7c\x20\x4d\x6f\x64\x65\x6c\x20\x7c\x20\x57\x6c\x61\x73\x63\x69\x63\x69\x65\x6c\x20\x20\x7c\x20\x44\x61\x74\x61\x20\x7c\x20\x4b\x6f\x6e\x74\x61\x6b\x74\x20\x7c\x20\x4b\x6f\x6d\x65\x6e\x74\x61\x72\x7a\x20\x7c\x20\x20\x20\x49\x44\x20\x7c\n");
  37. _w("\x7c\x20\x20\x20\x31\x20\x20\x20\x7c\x20\x20\x20\x32\x20\x20\x20\x7c\x20\x20\x20\x33\x20\x7c\x20\x20\x20\x34\x20\x20\x7c\x35\x7c\x20\x36\x20\x7c\x20\x20\x20\x37\x20\x20\x7c\n");
  38. _w("");int n;cin>>n;switch(n){_for 1:__(_db.begin(),_db.end(),&_tCM);lel;_for 2:__(_db.begin(),_db.end(),&_tCMo);lel;_for 3:__(_db.begin(),_db.end(),&_tCW);lel;_for 4:__(_db.begin(),_db.end(),&_tCD);lel;_for 5:__(_db.begin(),_db.end(),&_tCK);lel;_for 6:__(_db.begin(),_db.end(),&_tCKo);
  39. lel;_for 7:__(_db.begin(),_db.end(),&_iC);lel;}_w("Podaj spoosob sortowania bazy danych: a-z [AZ] | z-a [ZA]: ");string tmp;cin>>tmp;if(tmp=="AZ"||tmp=="az")_w("Baza posortowana od A do Z!\n");else if(tmp=="ZA"||tmp=="za"){reverse(_db.begin(),_db.end());_w("Baza posortowana od Z do A!\n");}else _w("Baza danych zostala posortowana domyslnie [a-z]\n");
  40. cin.ignore();}_V print(){cout<<"\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\n\x7c\x20\x20\x4d\x61\x72\x6b\x61\x20\x20\x20\x7c\x20\x20\x20\x4d\x6f\x64\x65\x6c\x20\x7c\x20\x20\x20\x57\x6c\x61\x73\x63\x69\x63\x69\x65\x6c\x20\x7c\x20\x20\x20\x44\x61\x74\x61\x20\x20\x7c\x20\x20\x20\x4b\x6f\x6e\x74\x61\x6b\x74\x20\x20\x7c\x20\x20\x20\x4b\x6f\x6d\x65\x6e\x74\x61\x72\x7a\x20\x20\x7c\x20\x20\x49\x44\x20\x20\x7c\n";
  41. _foreach(i,_db){ostringstream ss;ss<<i;string str = ss.str();printf("|%10.10s|%9.9s|%14.14s|%9.9s|%12.12s|%14.14s|%6.6s|\n",_db[i]._x_D.c_str(),_db[i]._0x1337.c_str(),_db[i]._n00b.c_str(),_db[i].___.c_str(),_db[i]._encore.c_str(),_db[i]._0x0.c_str(),str.c_str());}}
  42. _V _dm(){fstream plik;plik.open("___.base",ios::out| ios::trunc);if(plik.good()==false)_w("\x4e\x69\x65\x20\x6d\x6f\x7a\x6e\x61\x20\x75\x7a\x79\x73\x6b\x61\x63\x20\x64\x6f\x73\x74\x65\x70\x75\x20\x64\x6f\x20\x70\x6c\x69\x6b\x75\x21\n");
  43. else{_foreach(i,_db)plik<<_db[i]._x_D<<_SEP<<_db[i]._0x1337<<_SEP<<_db[i]._n00b<<_SEP<<_db[i].___<<_SEP<<_db[i]._encore<<_SEP<<_db[i]._0x0<<_SEP<<_db[i]._ID<<endl;
  44. _w("Baza danych zrzucona do pliku ___.base!\n");plik.close();}}_V load(){fstream plik;string _li;_BF bf;plik.open("___.base",ios::in);if(plik.good()==false)_w("\x4e\x69\x65\x20\x6d\x6f\x7a\x6e\x61\x20\x75\x7a\x79\x73\x6b\x61\x63\x20\x64\x6f\x73\x74\x65\x70\x75\x20\x64\x6f\x20\x70\x6c\x69\x6b\x75\x21\n");
  45. else{_db.clear();fag(_x_(plik,_li)){bf.nul();size_t found = _li.find(_SEP);for(int i=0;i<found;i++)bf._x_D+=_li[i];_li.erase(_li.begin(),_li.begin()+found+7);found = _li.find(_SEP);for(int i=0;i<found;i++)bf._0x1337+=_li[i];_li.erase(_li.begin(),_li.begin()+found+7);found = _li.find(_SEP);for(int i=0;i<found;i++)bf._n00b+=_li[i];_li.erase(_li.begin(),_li.begin()+found+7);found = _li.find(_SEP);for(int i=0;i<found;i++)bf.___+=_li[i];_li.erase(_li.begin(),_li.begin()+found+7);
  46. found = _li.find(_SEP);for(int i=0;i<found;i++)bf._encore+=_li[i];_li.erase(_li.begin(),_li.begin()+found+7);found = _li.find(_SEP);for(int i=0;i<found;i++)bf._0x0+=_li[i];_li.erase(_li.begin(),_li.begin()+found+7);
  47. bf._ID =ID++;_db.push_back(bf);}_w("Baza pomyslnie zaladowana!\n");plik.close();}}_V _ex(){_dm();_w("Dziekuje za prace");}_V edit(){__(_db.begin(),_db.end(),_iC);_w("Czy chcesz wyswietlic baze? [t/n] \n");_w("");char choice;cin>>choice;cin.ignore();if(choice == 't')
  48. print();_w("Podaj ID wpisu, ktory chcesz edytowac: ");int n;cin>>n;string in;cout<<"Marka: "<<_db[n]._x_D<<"\n\x50\x6f\x64\x61\x6a\x20\x6e\x6f\x77\x61\x20\x77\x61\x72\x74\x6f\x73\x63\x20\x64\x6c\x61\x20\x74\x65\x67\x6f\x20\x70\x6f\x6c\x61\x3a\x20\n";
  49. cin.ignore();_x_(cin,in);_db[n]._x_D = in;cout<<"Model: "<<_db[n]._0x1337<<"\n\x50\x6f\x64\x61\x6a\x20\x6e\x6f\x77\x61\x20\x77\x61\x72\x74\x6f\x73\x63\x20\x64\x6c\x61\x20\x74\x65\x67\x6f\x20\x70\x6f\x6c\x61\x3a\x20\n";
  50. _x_(cin,in);_db[n]._0x1337 = in;cout<<"Wlasciciel: "<<_db[n]._n00b<<"\n\x50\x6f\x64\x61\x6a\x20\x6e\x6f\x77\x61\x20\x77\x61\x72\x74\x6f\x73\x63\x20\x64\x6c\x61\x20\x74\x65\x67\x6f\x20\x70\x6f\x6c\x61\x3a\x20\n";
  51. _x_(cin,in);_db[n]._n00b = in;cout<<"Data: "<<_db[n].___<<"\n\x50\x6f\x64\x61\x6a\x20\x6e\x6f\x77\x61\x20\x77\x61\x72\x74\x6f\x73\x63\x20\x64\x6c\x61\x20\x74\x65\x67\x6f\x20\x70\x6f\x6c\x61\x3a\x20\n";
  52. _x_(cin,in);_db[n].___ = in;cout<<"Kontakt: "<<_db[n]._encore<<"\n\x50\x6f\x64\x61\x6a\x20\x6e\x6f\x77\x61\x20\x77\x61\x72\x74\x6f\x73\x63\x20\x64\x6c\x61\x20\x74\x65\x67\x6f\x20\x70\x6f\x6c\x61\x3a\x20\n";
  53. _x_(cin,in);_db[n]._encore = in;cout<<"Komentarz: "<<_db[n]._0x0<<"\n\x50\x6f\x64\x61\x6a\x20\x6e\x6f\x77\x61\x20\x77\x61\x72\x74\x6f\x73\x63\x20\x64\x6c\x61\x20\x74\x65\x67\x6f\x20\x70\x6f\x6c\x61\x3a\x20\n";
  54. _x_(cin,in);_db[n]._0x0 = in;}_X _iC(_BF nn, _BF rn){return nn._ID>rn._ID;}_X _tCM(_BF nn, _BF rn){int i=0;fag(nn._x_D[i]==rn._x_D[i])i++;if(i==nn._x_D.size()&&i<rn._x_D.size())_RT;if(nn._x_D[i]<rn._x_D[i])_RT;return false;}_X _tCMo(_BF nn, _BF rn){int i=0;fag(nn._0x1337[i]==rn._0x1337[i])i++;if(i==nn._0x1337.size()&&i<rn._0x1337.size())_RT;if(nn._0x1337[i]<rn._0x1337[i])_RT;return false;}_X _tCK(_BF nn, _BF rn){int i=0;fag(nn._encore[i]==rn._encore[i])i++;if(i==nn._encore.size()&&i<rn._encore.size())
  55. _RT;if(nn._encore[i]<rn._encore[i])_RT;return false;}_X _tCKo(_BF nn, _BF rn){int i=0;fag(nn._0x0[i]==rn._0x0[i])i++;if(i==nn._0x0.size()&&i<rn._0x0.size())_RT;if(nn._0x0[i]<rn._0x0[i])_RT;return false;}_X _tCW(_BF nn, _BF rn){int i=0;fag(nn._n00b[i]==rn._n00b[i])i++;if(i==nn._n00b.size()&&i<rn._n00b.size())
  56. _RT;if(nn._n00b[i]<rn._n00b[i])_RT;return false;}_X _tCD(_BF nn, _BF rn){int i=0;fag(nn.___[i]==rn.___[i])i++;if(i==nn.___.size()&&i<rn.___.size())_RT;if(nn.___[i]<rn.___[i])_RT;return false;}_V parseInput(string &in){(in=="/exit"?_ex():(in=="/help"?help():(in=="/add"?add():(in=="/sort"?_sort():(in=="/print"?print():(in=="/dump"?_dm():(in=="/load"?load():(in=="/edit"?edit():(in=="/search"?find():_w("Unknown command!\n"))))))))));}
  57. _V find(){vector<int> pos;string tmp;size_t found;cout<<"Marka: ";_x_(cin,tmp);_foreach(i,_db){found = _db[i]._x_D.find(tmp);if(found!=string::npos)pos.push_back(i);}cout<<"\nModel: ";_x_(cin,tmp);_foreach(i,pos){if(pos.empty()){cout<<"\x42\x52\x41\x4b\x20\x57\x59\x4e\x49\x4b\x4f\x57\x21\n";lel;}found = _db[pos[i]]._0x1337.find(tmp);if(found==string::npos){pos.erase(pos.begin()+i);
  58. i--;}}cout<<"\nWlasciciel: ";_x_(cin,tmp);_foreach(i,pos){if(pos.empty()){cout<<"\x42\x52\x41\x4b\x20\x57\x59\x4e\x49\x4b\x4f\x57\x21\n";lel;}found = _db[pos[i]]._n00b.find(tmp);if(found==string::npos){pos.erase(pos.begin()+i);i--;}}cout<<"\nData: ";_x_(cin,tmp);_foreach(i,pos){if(pos.empty()){cout<<"BRAK WYNIKOW!\n";
  59. lel;}found = _db[pos[i]].___.find(tmp);if(found==string::npos){pos.erase(pos.begin()+i);i--;}}cout<<"\nKontakt: ";_x_(cin,tmp);_foreach(i,pos){if(pos.empty()){cout<<"BRAK WYNIKOW!\n";lel;}found = _db[pos[i]]._encore.find(tmp);
  60. if(found==string::npos){pos.erase(pos.begin()+i);i--;}}cout<<"\nKomentarz: ";_x_(cin,tmp);_foreach(i,pos){if(pos.empty()){cout<<"BRAK WYNIKOW!\n";lel;}found = _db[pos[i]]._0x0.find(tmp);
  61. if(found==string::npos){pos.erase(pos.begin()+i);i--;}}if(pos.empty()){cout<<"Brak wynikow podczas wyszukiwania wedle zadanego kryterium.\n";}else{cout<<"\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\n\x7c\x20\x20\x4d\x61\x72\x6b\x61\x20\x20\x20\x7c\x20\x20\x20\x4d\x6f\x64\x65\x6c\x20\x7c\x20\x20\x20\x57\x6c\x61\x73\x63\x69\x63\x69\x65\x6c\x20\x7c\x20\x20\x20\x44\x61\x74\x61\x20\x20\x7c\x20\x20\x20\x4b\x6f\x6e\x74\x61\x6b\x74\x20\x20\x7c\x20\x20\x20\x4b\x6f\x6d\x65\x6e\x74\x61\x72\x7a\x20\x20\x7c\n";
  62. _foreach(i,pos)printf("|%10.10s|%9.9s|%14.14s|%9.9s|%12.12s|%14.14s|\n",_db[pos[i]]._x_D.c_str(),_db[pos[i]]._0x1337.c_str(),_db[pos[i]]._n00b.c_str(),_db[pos[i]].___.c_str(),_db[pos[i]]._encore.c_str(),_db[pos[i]]._0x0.c_str());}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement