Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class ReverseAvg {
- // :NOTE: naming -- it's better to name "matrix" not "mass", do not abbreviate words incomprehensibly
- public static long[][] addLineInMass(long[][] mass, int numStr) {
- // :NOTE: same -- naming
- if (mass.length == numStr + 1) {
- // :NOTE: mass1? -- not understandable name
- long[][] mass1 = new long[mass.length * 2][];
- for (int i = 0; i < mass.length; i++) {
- mass1[i] = new long[mass[i].length];
- System.arraycopy(mass[i], 0, mass1[i], 0, mass[i].length);
- }
- Arrays.fill(mass1, mass.length, mass.length*2, new long[1]);
- mass = mass1;
- }
- return mass;
- }
- // :NOTE: same -- naming
- public static long[] addDigitInMass(long[] mass, int numDig) {
- if (mass.length == numDig + 1) {
- // :NOTE: same -- naming
- long[] mass1 = new long[mass.length * 2];
- System.arraycopy(mass, 0, mass1, 0, mass.length);
- mass = mass1;
- }
- return mass;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- // :NOTE: same -- naming (massiv is not a word from English)
- long[][] mass = new long[1][1];
- // :NOTE: same -- naming
- long[] massSize = new long[1];
- long[] numbersInColumns = new long[1];
- long[] sumColumn = new long[1];
- long[] sumString = new long[1];
- int numStr = 0;
- int numElem = 0;
- while (in.hasNextLine()) {
- Scanner str = new Scanner(in.nextLine());
- while (str.hasNextInt()) {
- mass[numStr][numElem] = str.nextInt();
- sumString[numStr] +=mass[numStr][numElem];
- sumColumn[numElem] += mass[numStr][numElem];
- numbersInColumns[numElem]++;
- sumColumn = addDigitInMass(sumColumn, numElem);
- numbersInColumns = addDigitInMass(numbersInColumns, numElem);
- mass[numStr] = addDigitInMass(mass[numStr], numElem);
- numElem++;
- }
- mass = addLineInMass(mass, numStr);
- massSize = addDigitInMass(massSize, numStr);
- sumString = addDigitInMass(sumString, numStr);
- massSize[numStr] = numElem;
- numStr++;
- numElem = 0;
- }
- // :NOTE: your scanner is not used in the next "for" block of code, so you should close it here
- for (int i = 0; i < numStr; i++) {
- for (int j = 0; j < massSize[i]; j++) {
- System.out.print((sumString[i] + sumColumn[j] - mass[i][j])/(numbersInColumns[j] + massSize[i] - 1) + " ");
- }
- System.out.println();
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement