Advertisement
a53

potrivire_eu

a53
Feb 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <fstream>
  2. #define N 1000001
  3. using namespace std;
  4. int a[N],F[N];
  5.  
  6. int main()
  7. {
  8. ifstream f("potrivire.in");
  9. int n;
  10. f>>n;
  11. for(int i=1;i<=n;++i)
  12. f>>a[i],F[a[i]]=1;
  13. for(int i=1;i<=n-1;++i)
  14. F[a[i]*10+a[i+1]]=1;
  15. for(int i=1;i<=n-2;++i)
  16. F[a[i]*100+a[i+1]*10+a[i+2]]=1;
  17. for(int i=1;i<=n-3; ++i)
  18. F[a[i]*1000+a[i+1]*100+a[i+2]*10+a[i+3]]=1;
  19. for(int i=1;i<=n-4;++i)
  20. F[a[i]*10000+a[i+1]*1000+a[i+2]*100+a[i+3]*10+a[i+4]]=1;
  21. int m,x,suma=0;;
  22. f>>m;
  23. while(m--)
  24. {
  25. f>>x;
  26. if(F[x])
  27. suma+=x,F[x]=0;
  28. }
  29. f.close();
  30. ofstream g("potrivire.out");
  31. g<<suma<<'\n';
  32. g.close();
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement