Guest User

Untitled

a guest
Mar 20th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void podajNapisy(string &napis1, string &napis2);
  7. void utworz_macierz(string napis1, string napis2);
  8. void wypelnij_macierz(vector<vector<int> > &macierz, int r, int t, string napis1, string napis2);
  9. void zapisz_wynik_do_tablicy(vector<vector<int> > macierz, int r, int t, string napis1);
  10.  
  11. int main()
  12. {
  13.     string napis1, napis2;
  14.  
  15.     podajNapisy(napis1, napis2);
  16.     utworz_macierz(napis1, napis2);
  17.  
  18.     return 0;
  19. }
  20.  
  21. void podajNapisy(string &napis1, string &napis2)
  22. {
  23.     cout<<"Wprowadz napisy: "; cin>>napis1; cin>>napis2; cout<<endl;
  24. }
  25. void utworz_macierz(string napis1, string napis2)
  26. {
  27.     int r = napis1.size();
  28.     int t = napis2.size();
  29.  
  30.     vector <int> q(r+1);
  31.     vector<vector<int> > macierz(t+1,q);
  32.  
  33.     wypelnij_macierz(macierz ,r ,t, napis1, napis2);
  34. //    zapisz_wynik_do_tablicy(macierz, r, t, napis1);
  35. }
  36.  
  37. void wypelnij_macierz(vector<vector<int> > &macierz, int r, int t, string napis1, string napis2)
  38. {
  39.  
  40.     for(int i = 0; i <= r; i++)
  41.     {
  42.         for(int j = 0; j <= t; j++)
  43.         {
  44.                 macierz[i][j] = 0;
  45.         }
  46.     }
  47.  
  48.     for(int i = 1; i <= r; i++)
  49.     {
  50.         cout<<endl;
  51.         for(int j = 1; j <= t; j++)
  52.         {
  53.             if(napis1[i] == napis2[i]){ macierz[i][j] = (macierz[i-1][j-1]) +1;}
  54.             else {macierz[i][j] = max(macierz[i][j-1], macierz[i-1][j]);}
  55.             cout<<macierz[i][j];
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment