SHARE
TWEET

Potrivire_Of

a53 Feb 23rd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <cassert>
  5.  
  6. using namespace std;
  7.  
  8. ifstream fin("potrivire.in");
  9. ofstream fout("potrivire.out");
  10.  
  11. int n, A[100001], m, x;
  12. int S = 0;
  13. int v[100000];
  14.  
  15. int main()
  16. {
  17.     fin >> n;
  18.     for(int i = 1; i <= n ; i ++)
  19.     {
  20.         fin >> A[i];
  21.         assert(A[i] >= 0 && A[i] <= 9);
  22.     }
  23.     for(int i = 1 ; i <= n ; i ++)
  24.         v[A[i]] = 1;
  25.     for(int i = 1 ; i <= n - 1; i ++)
  26.         v[A[i]*10 + A[i+1]] = 1;
  27.     for(int i = 1 ; i <= n - 2; i ++)
  28.         v[A[i]*100 + A[i+1]*10+A[i+2]] = 1;
  29.     for(int i = 1 ; i <= n - 3; i ++)
  30.         v[A[i]*1000 + A[i+1]*100+A[i+2]*10+A[i+3]] = 1;
  31.     for(int i = 1 ; i <= n - 4; i ++)
  32.         v[A[i]*10000 + A[i+1]*1000 + A[i+2]*100 + A[i+3]*10 +A[i+4]] = 1;
  33.    
  34.     for(fin >> m; m ; m --)
  35.     {
  36.         fin >> x;
  37.         assert(x >= 0 && x <= 99999);
  38.         if(v[x])
  39.             S += x, v[x] = 0;
  40.     }
  41.    
  42.     fout << S << "\n";
  43.    
  44.     fin.close();
  45.     fout.close();
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top