Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg33;
- /**
- *
- * @author Acer
- */
- import java.io.*;
- public class Main {
- public static void main(String[] args) {
- try
- {
- if (args.length != 2) throw new IncorrectLengthException();
- InputStream fin = new FileInputStream(args[0]);
- Matrix A = Matrix.input(fin);
- fin.close();
- A = Matrix.Func(A);
- OutputStream fout = new FileOutputStream(args[1]);
- A.output(fout);
- fout.close();
- }
- catch (IncorrectLengthException Exc){System.out.println(Exc.getMessage());}
- catch (FileNotFoundException Exc){System.out.println("Отсутствует входной файл!");}
- catch (Exception Exc) {System.out.println(Exc.getMessage());}
- }
- }
- class IncorrectLengthException extends Exception {
- public IncorrectLengthException() {
- super ("Неверное число аргументов!");
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package pkg33;
- /**
- *
- * @author Acer
- */
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.Random;
- public class Matrix implements Serializable{
- private static double[][] arr;
- private static int m;
- private static int n;
- Matrix(int m, int n) {
- Random rnd = new Random();
- arr = new double[m][n];
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- arr[i][j]=rnd.nextDouble();
- }
- }
- }
- public int getCol(){
- return n;
- }
- public int getRow(){
- return m;
- }
- public void setArr(double value, int i, int j) {
- arr[i][j] = value;
- }
- public double getArr(int i, int j) {
- return arr[i][j];
- }
- static Matrix Func(Matrix matr){
- ArrayList<Integer> row = new ArrayList<>();
- ArrayList<Integer> col = new ArrayList<>();
- for(int i=0; i<matr.m;i++){
- for(int j=0; j<matr.n;i++){
- if(matr.getArr(i,j) == 0){
- row.add(i);
- col.add(j);
- }
- }
- }
- for (int i = 0; i <row.size() ; i++) {
- for (int j = 0; j <matr.getCol() ; j++) {
- matr.setArr(row.get(i), j, 0);
- }
- }
- for (int i = 0; i <col.size() ; i++) {
- for (int j = 0; j <matr.m ; j++) {
- matr.setArr(j, col.get(i), 0);
- }
- } return matr;
- }
- public void output(OutputStream out) throws IOException{
- DataOutputStream Dout = new DataOutputStream(out);
- Dout.writeInt(getRow());
- Dout.writeInt(getCol());
- for(int i = 0; i< getCol(); i++)
- for(int j = 0; j< getRow(); j++)
- Dout.writeDouble(arr[i][j]);
- Dout.close();
- }
- public static Matrix input(InputStream inp) throws IOException{
- DataInputStream Dinp = new DataInputStream(inp);
- int n = Dinp.readInt();
- int m = Dinp.readInt();
- Matrix Mat = new Matrix(m,n);
- for (int i = 0; i<m; i++)
- for(int j = 0; j<n;j++)
- Mat.setArr(Dinp.readDouble(),i,j);
- Dinp.close();
- return Mat;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement