Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void podajNapisy(string &napis1, string &napis2);
- void utworz_macierz(string napis1, string napis2);
- void wypelnij_macierz(vector<vector<int> > &macierz, int r, int t, string napis1, string napis2);
- void zapisz_wynik_do_tablicy(vector<vector<int> > macierz, int r, int t, string napis1);
- int main()
- {
- string napis1, napis2;
- podajNapisy(napis1, napis2);
- utworz_macierz(napis1, napis2);
- return 0;
- }
- void podajNapisy(string &napis1, string &napis2)
- {
- cout<<"Wprowadz napisy: "; cin>>napis1; cin>>napis2; cout<<endl;
- }
- void utworz_macierz(string napis1, string napis2)
- {
- int r = napis1.size();
- int t = napis2.size();
- vector <int> q(r+1);
- vector<vector<int> > macierz(t+1,q);
- wypelnij_macierz(macierz ,r ,t, napis1, napis2);
- // zapisz_wynik_do_tablicy(macierz, r, t, napis1);
- }
- void wypelnij_macierz(vector<vector<int> > &macierz, int r, int t, string napis1, string napis2)
- {
- for(int i = 0; i <= r; i++)
- {
- for(int j = 0; j <= t; j++)
- {
- macierz[i][j] = 0;
- }
- }
- for(int i = 1; i <= r; i++)
- {
- cout<<endl;
- for(int j = 1; j <= t; j++)
- {
- if(napis1[i] == napis2[i]){ macierz[i][j] = (macierz[i-1][j-1]) +1;}
- else {macierz[i][j] = max(macierz[i][j-1], macierz[i-1][j]);}
- cout<<macierz[i][j];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment