Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("potrivire.in");
- ofstream g("potrivire.out");
- int n,m,x,nr,sum;
- string cif,str;
- unordered_map<string,bool> M;
- int main()
- {
- f>>n;
- cif+='0';
- for (int i=1;i<=n;++i)
- f>>x,cif+=char(x+'0');
- for(int i=1;i<=n;++i)
- {
- str.clear();
- for (int j=0;i+j<=n&&j<5;++j)
- str+=cif[i+j],M[str]=true;
- }
- f>>m;
- for(int i=1;i<=m;++i)
- {
- f>>str;
- if(M[str])
- {
- nr=0;
- for(size_t j=0;j<str.size();++j)
- nr=nr*10+str[j]-'0';
- sum+=nr;
- M[str]=false;
- }
- }
- g<<sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement