fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. int k=33;
  15. vector<int>a={9, 4, 20, 3, 10, 5};
  16. int n=a.size();
  17. map<int,int>mp;
  18. mp[0]=1;
  19. int count=0;
  20. int sum=0;
  21. for(int i=0;i<n;i++){
  22. sum=sum+a[i];
  23. if(mp.find(sum-k)!=mp.end()){
  24. count+=mp[sum-k];
  25. }
  26. mp[sum]++;
  27. }
  28.  
  29. cout<<count<<endl;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
2