Codeforces 18C Solution

Solve in C++:

  1. ///**********ALLAH IS ALMIGHTY************///
  2. ///AH Tonmoy
  3. ///Department of CSE
  4. ///Islamic University,Bangladesh
  5. #include<iostream>
  6. #include<math.h>
  7. #include<algorithm>
  8. using namespace std;
  9. int main()
  10. {
  11. int n,i,a[100009],s1=0,s=0,r=0,div,c=0;
  12. cin>>n;s=0;
  13. for(i=0; i<n; i++)
  14. { cin>>a[i];
  15. s=s+a[i];
  16. }
  17. if(s%2==1)
  18. { cout<<"0"<<endl;
  19. return 0;
  20. }
  21. else
  22. {
  23.   for(i=0; i<n-1; i++)
  24. { s1+=a[i];
  25. s-=a[i];
  26. if(s1==s)
  27. r++;
  28. }
  29. cout<<r<<endl;
  30. return 0;
  31. }
  32. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.