fork download
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cin>>n;
  7. int **a = new int*[n];
  8. for (int i=0;i<n;i++)
  9. a[i] = new int [n];
  10.  
  11. int *b = new int [n];
  12.  
  13. for(int i = 0; i < n; i++){
  14. a[i] = new int [n];
  15. b[i] = 0;
  16. for(int j = 0; j < n; j++){
  17. cin>>a[i][j];
  18. }
  19. }
  20. for(int i = 0; i < n; i++){
  21. if(a[i][i] < 0){
  22. for(int j = 0; j < i; j++){
  23. if(a[i][j] < 0) break;
  24. b[i]+=a[i][j];
  25. }
  26. }
  27. else{
  28. int k;
  29. for(k = 0; k < n; k++){
  30. if(a[i][k] >= 0) break;
  31. }
  32. for(int j = k; j < n; j++){
  33. b[i]+=a[i][j];
  34. }
  35. }
  36. }
  37. for(int i = 0; i < n; i++){
  38. cout<<b[i]<<" ";
  39. }
  40. }
  41.  
Success #stdin #stdout 0s 3416KB
stdin
3 
1 -2 3
-7 -3 0
5 5 2
stdout
2 0 12