Stupid c++ solution


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include<cstdio>
  2.  
  3. using namespace std;
  4. #define max1(x,y) (x)<(y)?(y):(x)
  5. #define min1(x,y) (x)>(y)?(y):(x)
  6. int z[1000000];
  7.  
  8. int main(){
  9. freopen("input.txt","r",stdin);
  10. freopen("output.txt","w",stdout);
  11. int sum=0;
  12. int n,min,max;
  13. min=max=0;
  14. scanf("%d",&n);
  15. for(int i=0; i<n; i++){
  16. scanf("%d",&z[i]);
  17. if(z[i]>0)sum+=z[i];
  18. if(z[i]<z[min])min=i;
  19. if(z[i]>z[max])max=i;
  20. }
  21. printf("%d ",sum);
  22. sum=1;
  23. if(min<max){
  24. for(int i=min+1; i<max; i++){
  25. sum*=z[i];
  26. }
  27. }else{
  28. for(int i=max+1; i<min; i--){
  29. sum*=z[i];
  30. }
  31. }
  32. printf("%d\n",sum);
  33. return 0;
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.