daily pastebin goal
63%
SHARE
TWEET

Potrivire_ajutor

a53 Feb 23rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("potrivire.in");
  4. ofstream g("potrivire.out");
  5. int n,m,x,nr,sum;
  6. string cif,str;
  7. unordered_map<string,bool> M;
  8.  
  9. int main()
  10. {
  11.     f>>n;
  12.     cif+='0';
  13.     for (int i=1;i<=n;++i)
  14.         f>>x,cif+=char(x+'0');
  15.     for(int i=1;i<=n;++i)
  16.     {
  17.         str.clear();
  18.         for (int j=0;i+j<=n&&j<5;++j)
  19.             str+=cif[i+j],M[str]=true;
  20.     }
  21.     f>>m;
  22.     for(int i=1;i<=m;++i)
  23.     {
  24.         f>>str;
  25.         if(M[str])
  26.         {
  27.             nr=0;
  28.             for(size_t j=0;j<str.size();++j)
  29.                 nr=nr*10+str[j]-'0';
  30.             sum+=nr;
  31.             M[str]=false;
  32.         }
  33.     }
  34.     g<<sum;
  35. }
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