Left Sum and Right Sum
unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
import java.io.*; import java.util.*; public class si1{ public static void main(String[] args) { int n; Scanner sc = new Scanner(System.in); n = sc.nextInt(); int[] ar = new int[n]; for(int i = 0;i < n;i++){ ar[i] = sc.nextInt(); } int[] leftSum = new int[n]; int[] rightSum = new int[n]; for(int i = 0;i < n;i++){ if(i == 0){ leftSum[i] = 0; for(int j = 1;j < n;j++){ rightSum[i] += ar[j]; } } else if(i == n - 1){ rightSum[i] = 0; for(int j = 0;j < n - 1;j++){ leftSum[i] += ar[j]; } } else{ for(int j = 0;j < i ;j++){ leftSum[i] += ar[j]; } for(int j = i + 1;j < n;j++){ rightSum[i] += ar[j]; } } } //for(int i = 0;i < n;i++){ // System.out.print(leftSum[i] + " "); //} //System.out.println(); //for(int i = 0;i < n;i++){ // System.out.print(rightSum[i] + " "); //} //System.out.println(); for(int i = 0;i < n;i++){ System.out.print(Math.abs(leftSum[i] - rightSum[i]) + " "); } } }