Guest User

Untitled

a guest
May 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. using namespace std;
  5. void fun1();
  6. void znajdz( char element, string tresc);
  7. main()
  8. {
  9.     int a,b;
  10.  
  11.     cout << "Pracownik" << endl;
  12.     cout << "Klient" << endl;
  13.     cin >> a;
  14.     if(a==1)
  15.     {
  16.         cout << "1. Wprowadz kasiazke" << endl;
  17.         cout << "2. Usun ksiazke" << endl;
  18.         cout << "3. Wyszukaj" << endl;
  19.         cin >> b;
  20.         if(b==1)
  21.         {
  22.             fun1();
  23.         }
  24.     }
  25.  
  26. }
  27. void fun1()
  28. {
  29.     glowny = glowny + "<k>";
  30.     string tytul;
  31.     string autor;
  32.  
  33.     cin >> tytul;
  34.     cin >> autor;
  35.  
  36.     glowny = glowny + "<t>" + tytul + "<t>";
  37.     glowny = glowny + "<a>" + autor + "<a>";
  38.     glowny = glowny + "<k>";
  39. }
  40. void znajdz( char element, string tresc)
  41. {
  42.     string szukany = "";
  43.  
  44.     switch( element )
  45.     {
  46.     case 't':
  47.         szukany = szukany + "<t>" + tytul + "<t>";
  48.         break;
  49.  
  50.     case 'a':
  51.         szukany = szukany + "<a>" + autor + "<a>";
  52.         break;
  53.     }
  54.  
  55.     int znaleziony = glowny.find( szukany );
  56.  
  57.     string przed = glowny.substr( 0,( znaleziony - 1 ) );
  58.     int poczatekPozycji = przed.rfind( "<k>" );
  59.  
  60.     string po = glowny.substr(( znaleziony - 1 ),( glowny.length() - 1 ) );
  61.     int koniecPozycji = znaleziony + po.find( "<k>" );
  62.  
  63.     string pozycja = glowny.substr( poczatekPozycji,( koniecPozycji - poczatekPozycji ) );
  64.  
  65.     int koniecTytulu = pozycja.find_last_of( 't' );
  66.     cout << pozycja.substr( 6,( koniecTytulu - 2 ) ) << endl;
  67.     cout << pozycja.substr(( koniecTytulu + 2 ),( pozycja.length() - 6 ) );
  68. }
Add Comment
Please, Sign In to add comment