Advertisement
AkirusG

Untitled

Nov 16th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <limits>
  7. #include <map>
  8. #include <cstdlib>
  9. #include <cmath>
  10. #include <set>
  11. #include <bitset>
  12. #include <string>
  13. #include <iomanip>
  14. #include <deque>
  15.  
  16. using namespace std;
  17.  
  18. template<class T>
  19. ostream& operator<<(ostream& is, vector<T> v){
  20.     for(int i = 0; i < v.size(); i++){
  21.         is << v[i];
  22.     }
  23.     return is;
  24. }
  25.  
  26.  
  27.  
  28. int main(){
  29.     //freopen("", "r", stdin); freopen("", "w", stdout);
  30.     //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  31.     ios::sync_with_stdio(false);
  32.  
  33.     int n, m;
  34.    
  35.     cin >> n;
  36.     vector<int> a(n);
  37.     for(int i = 0; i < n; i++)
  38.         cin >> a[i];
  39.    
  40.     cin >> m;
  41.     vector<int> b(m);
  42.     for(int i = 0; i < m; i++)
  43.         cin >> b[i];
  44.    
  45.     vector<vector<int> > mat(n, vector<int>(m, 0));
  46.    
  47.     for(int i = 0; i < n; i++){
  48.         for(int j = 0; j < m; j++){
  49.             if(a[i] == b[j]){
  50.                 mat[i][j] = 1 + (j > 0 && i > 0 ? mat[i-1][j-1] : 0);
  51.                // cout << i <<  " " << j;
  52.             }
  53.         }
  54.     }
  55.    
  56. //    for(int i = 0; i < n; i++){
  57. //        for(int j = 0; j < m; j++){
  58. //            cout << mat[i][j] << " ";
  59. //        }
  60. //        cout << endl;
  61. //    }
  62. //    
  63.     int mx = 0;
  64.     int mi = 0;
  65.    
  66.     for(int i = 0; i < n; i++){
  67.         for(int j = 0; j < m; j++){
  68.             if(mat[i][j] > mx){
  69.                 mx = mat[i][j];
  70.                 mi = i;
  71.             }
  72.         }
  73.     }
  74.    
  75.     for(int i = mi - mx + 1; i <= mi; i++)
  76.         cout << a[i] << " ";
  77.    
  78.     return  0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement