Advertisement
encoree1996

Untitled

May 18th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.30 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. using namespace std;
  17. int ID = 0;
  18. class _BF{
  19. public:
  20. string _x_D, _0x1337, _n00b, ___, _encore,_0x0;int _ID;
  21. _BF(){_x_D=_0x1337=_n00b=___=_encore=_0x0=" ";_ID = ID++;}_V nul()
  22. {_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);
  26. _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);
  27. parseInput(n);if(n=="/_ex")break;_w("");}return 0;}_V _w(string in){cout<<"> "<<in;}
  28. _V help(){__(_cmd.begin(),_cmd.end());_w("Dostepne komendy: \n");_w("");_foreach(i,_cmd)
  29. cout<<_cmd[i]<<" ";cout<<endl;_w("");}_V add(){string in="";char choice;_BF bf;
  30. _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;
  31. _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;
  32. _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;
  33. _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;
  34. _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;
  35. _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);
  36. _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\x5c\x6e");}_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\x5c\x6e");
  37. _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\x5c\x6e");
  38. _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\x5c\x6e");
  39. _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\x5c\x6e");
  40. _w("");int n;cin>>n;switch(n){case 1:__(_db.begin(),_db.end(),&_tCM);break;case 2:__(_db.begin(),_db.end(),&_tCMo);
  41. break;case 3:__(_db.begin(),_db.end(),&_tCW);break;case 4:__(_db.begin(),_db.end(),&_tCD);break;case 5:__(_db.begin(),_db.end(),&_tCK);break;case 6:__(_db.begin(),_db.end(),&_tCKo);
  42. break;case 7:__(_db.begin(),_db.end(),&_iC);break;}_w("Podaj spoosob sortowania bazy danych: a-z [AZ] | z-a [ZA]: ");
  43. 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");
  44. 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\x5c\x6e\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\x5c\x6e";
  45. _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());}}
  46. _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\x5c\x6e");
  47. 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;
  48. _w("Baza danych zrzucona do pliku ___.base!\n");plik.close();}}_V load(){fstream plik;
  49. 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\x5c\x6e");
  50. else{_db.clear();while(_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);
  51. 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);
  52. 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);
  53. 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')
  54. print();_w("Podaj ID wpisu, ktory chcesz edytowac: ");int n;cin>>n;string in;cout<<"Marka: "<<_db[n]._x_D<<"\x5c\x6e\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\x5c\x6e";
  55. cin.ignore();_x_(cin,in);_db[n]._x_D = in;cout<<"Model: "<<_db[n]._0x1337<<"\x5c\x6e\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\x5c\x6e";
  56. _x_(cin,in);_db[n]._0x1337 = in;cout<<"Wlasciciel: "<<_db[n]._n00b<<"\x5c\x6e\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\x5c\x6e";
  57. _x_(cin,in);_db[n]._n00b = in;cout<<"Data: "<<_db[n].___<<"\x5c\x6e\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\x5c\x6e";
  58. _x_(cin,in);_db[n].___ = in;cout<<"Kontakt: "<<_db[n]._encore<<"\x5c\x6e\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\x5c\x6e";
  59. _x_(cin,in);_db[n]._encore = in;cout<<"Komentarz: "<<_db[n]._0x0<<"\x5c\x6e\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\x5c\x6e";
  60. _x_(cin,in);_db[n]._0x0 = in;}_X _iC(_BF left, _BF right){return left._ID>right._ID;}_X _tCM(_BF left, _BF right){int i=0;while(left._x_D[i]==right._x_D[i])
  61. i++;if(i==left._x_D.size()&&i<right._x_D.size())_RT;if(left._x_D[i]<right._x_D[i])_RT;return false;}_X _tCMo(_BF left, _BF right){
  62. int i=0;while(left._0x1337[i]==right._0x1337[i])i++;if(i==left._0x1337.size()&&i<right._0x1337.size())_RT;if(left._0x1337[i]<right._0x1337[i])_RT;return false;}_X _tCK(_BF left, _BF right){int i=0;while(left._encore[i]==right._encore[i])i++;if(i==left._encore.size()&&i<right._encore.size())
  63. _RT;if(left._encore[i]<right._encore[i])_RT;return false;}_X _tCKo(_BF left, _BF right){int i=0;while(left._0x0[i]==right._0x0[i])i++;if(i==left._0x0.size()&&i<right._0x0.size())
  64. _RT;if(left._0x0[i]<right._0x0[i])_RT;return false;}_X _tCW(_BF left, _BF right){int i=0;while(left._n00b[i]==right._n00b[i])i++;if(i==left._n00b.size()&&i<right._n00b.size())
  65. _RT;if(left._n00b[i]<right._n00b[i])_RT;return false;}_X _tCD(_BF left, _BF right){int i=0;while(left.___[i]==right.___[i])i++;if(i==left.___.size()&&i<right.___.size())
  66. _RT;if(left.___[i]<right.___[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"))))))))));}
  67. _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);
  68. 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\x5c\x6e";
  69. break;}found = _db[pos[i]]._0x1337.find(tmp);if(found==string::npos){pos.erase(pos.begin()+i);
  70. 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\x5c\x6e";
  71. break;}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";
  72. break;}found = _db[pos[i]].___.find(tmp);if(found==string::npos){pos.erase(pos.begin()+i);
  73. i--;}}cout<<"\nKontakt: ";_x_(cin,tmp);_foreach(i,pos){if(pos.empty()){cout<<"BRAK WYNIKOW!\n";break;}found = _db[pos[i]]._encore.find(tmp);
  74. 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";break;}found = _db[pos[i]]._0x0.find(tmp);
  75. if(found==string::npos){pos.erase(pos.begin()+i);i--;}}if(pos.empty()){cout<<"Brak wynikow podczas wyszukiwania wedle zadanego kryterium.\n";
  76. }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\x5c\x6e\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\x5c\x6e";
  77. _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