{"action":"created","comment":{"url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/comments/194240689","pull_request_review_id":127380318,"id":194240689,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDI0MDY4OQ==","diff_hunk":"@@ -0,0 +1,132 @@\n+package com.epam.homework;\n+\n+import java.util.HashSet;\n+import java.util.Scanner;\n+import java.util.Set;\n+\n+public class Task19 {\n+\n+    /**\n+     * Уплотнить матрицу, удаляя из нее строки и столбцы, заполненные нулями.\n+     * Гарантируется что после уплотнения в матрице останется хотя бы один элемент.\n+     * <a href=\"https://github.com/elefus/epam-core-04-2018/wiki/Представление-матриц\">Представление матриц</a>\n+     *\n+     * Формат входных данных:\n+     * N - целое число (0 < N < 10)\n+     * N ^ 2 целых чисел (Integer.MIN_VALUE < element < Integer.MAX_VALUE)\n+     *\n+     * Формат выходных данных:\n+     * В результате выполнения задания в выходной поток должна быть выведена преобразованная матрица.\n+     * Так как матрица в результате преобразования может перестать быть квадратной - несколько изменяется формат её представления:\n+     * N (целое число) - количество строк\n+     * M (целое число) - количество столбцов\n+     * N * M целых чисел, являющихся элементами матрицы\n+     *\n+     * ---------------------------------------------------------------------------------------------------\n+     * Примеры выполнения задания:\n+     *\n+     * Входные данные:\n+     *  4\n+     *  2  0  0 -1\n+     *  0  0  0  0\n+     *  0  0  0  3\n+     * -3  0  0  1\n+     *\n+     * Выходные данные:\n+     *  3\n+     *  2\n+     *  2 -1\n+     *  0  3\n+     * -3  1\n+     */\n+    public static void main(String[] args) {\n+        Scanner scanner = new Scanner(System.in);\n+        int[][] matrix = readMatrix(scanner);\n+        int[][] packedMatrix = pack(matrix);\n+\n+        System.out.println(packedMatrix.length);\n+        System.out.println(packedMatrix[0].length);\n+        print(packedMatrix);\n+    }\n+\n+    private static int[][] readMatrix(Scanner scanner) {\n+        int dimension = scanner.nextInt();\n+        int[][] matrix = new int[dimension][dimension];\n+\n+        for (int i = 0; i < dimension; i++) {\n+            for (int j = 0; j < dimension; j++) {\n+                matrix[i][j] = scanner.nextInt();\n+            }\n+        }\n+\n+        return matrix;\n+    }\n+\n+    private static int[][] pack(int[][] matrix) {\n+        Pair<Set<Integer>, Set<Integer>> rowsAndColumnsToRemain = getNotNullRowsAndColumnsOf(matrix);\n+        Set<Integer> rowsToRemain = rowsAndColumnsToRemain.getFirst();\n+        Set<Integer> columnsToRemain = rowsAndColumnsToRemain.getSecond();\n+        int[][] packedMatrix = new int[rowsToRemain.size()][columnsToRemain.size()];\n+\n+        for (int rowN = 0, newRowN = 0; rowN < matrix.length; rowN++) {\n+            if (!rowsToRemain.contains(rowN)) {\n+                continue;\n+            }\n+\n+            for (int columnN = 0, newColumnN = 0; columnN < matrix[0].length; columnN++) {\n+                if (!columnsToRemain.contains(columnN)) {\n+                    continue;\n+                }\n+\n+                packedMatrix[newRowN][newColumnN] = matrix[rowN][columnN];\n+                newColumnN++;\n+            }\n+            newRowN++;\n+        }\n+\n+        return packedMatrix;\n+    }\n+\n+    private static Pair<Set<Integer>, Set<Integer>> getNotNullRowsAndColumnsOf(int[][] matrix) {\n+        Set<Integer> notNullrows = new HashSet<>();\n+        Set<Integer> notNullcolumns = new HashSet<>();\n+\n+        for (int i = 0; i < matrix.length; i++) {\n+            for (int j = 0; j < matrix[0].length; j++) {\n+                if (matrix[i][j] != 0) {\n+                    notNullrows.add(i);\n+                    notNullcolumns.add(j);\n+                }\n+            }\n+        }\n+\n+        return new Pair<>(notNullrows, notNullcolumns);\n+    }\n+\n+    private static void print(int[][] matrix) {\n+        for (int[] row : matrix) {\n+            for (int el : row) {\n+                System.out.printf(\"%4d\", el);\n+            }\n+            System.out.println();\n+        }\n+    }\n+\n+    static class Pair <F, S> {","path":"src/main/java/com/epam/homework/Task19.java","position":115,"original_position":115,"commit_id":"84583dd45e0c2f20aed5e525ecda6a0b033e06da","original_commit_id":"84583dd45e0c2f20aed5e525ecda6a0b033e06da","user":{"login":"Ilya21","id":12701018,"node_id":"MDQ6VXNlcjEyNzAxMDE4","avatar_url":"https://avatars1.githubusercontent.com/u/12701018?v=4","gravatar_id":"","url":"https://api.github.com/users/Ilya21","html_url":"https://github.com/Ilya21","followers_url":"https://api.github.com/users/Ilya21/followers","following_url":"https://api.github.com/users/Ilya21/following{/other_user}","gists_url":"https://api.github.com/users/Ilya21/gists{/gist_id}","starred_url":"https://api.github.com/users/Ilya21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ilya21/subscriptions","organizations_url":"https://api.github.com/users/Ilya21/orgs","repos_url":"https://api.github.com/users/Ilya21/repos","events_url":"https://api.github.com/users/Ilya21/events{/privacy}","received_events_url":"https://api.github.com/users/Ilya21/received_events","type":"User","site_admin":false},"body":"А чего lombok не заюзал?","created_at":"2018-06-09T22:46:04Z","updated_at":"2018-06-09T22:47:17Z","html_url":"https://github.com/elefus/epam-core-04-2018/pull/394#discussion_r194240689","pull_request_url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/comments/194240689"},"html":{"href":"https://github.com/elefus/epam-core-04-2018/pull/394#discussion_r194240689"},"pull_request":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394"}}},"pull_request":{"url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394","id":193442280,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNDQyMjgw","html_url":"https://github.com/elefus/epam-core-04-2018/pull/394","diff_url":"https://github.com/elefus/epam-core-04-2018/pull/394.diff","patch_url":"https://github.com/elefus/epam-core-04-2018/pull/394.patch","issue_url":"https://api.github.com/repos/elefus/epam-core-04-2018/issues/394","number":394,"state":"open","locked":false,"title":"com.epam.homework.task19 (telnov)","user":{"login":"StasTelnov","id":3819003,"node_id":"MDQ6VXNlcjM4MTkwMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/3819003?v=4","gravatar_id":"","url":"https://api.github.com/users/StasTelnov","html_url":"https://github.com/StasTelnov","followers_url":"https://api.github.com/users/StasTelnov/followers","following_url":"https://api.github.com/users/StasTelnov/following{/other_user}","gists_url":"https://api.github.com/users/StasTelnov/gists{/gist_id}","starred_url":"https://api.github.com/users/StasTelnov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StasTelnov/subscriptions","organizations_url":"https://api.github.com/users/StasTelnov/orgs","repos_url":"https://api.github.com/users/StasTelnov/repos","events_url":"https://api.github.com/users/StasTelnov/events{/privacy}","received_events_url":"https://api.github.com/users/StasTelnov/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-06-07T20:45:26Z","updated_at":"2018-06-09T22:47:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4a6a2f91e31778e95f1319973a025c254a7424b1","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":902536620,"node_id":"MDU6TGFiZWw5MDI1MzY2MjA=","url":"https://api.github.com/repos/elefus/epam-core-04-2018/labels/4.%20Users%20approved%202/3","name":"4. Users approved 2/3","color":"fbca04","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394/commits","review_comments_url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394/comments","review_comment_url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elefus/epam-core-04-2018/issues/394/comments","statuses_url":"https://api.github.com/repos/elefus/epam-core-04-2018/statuses/84583dd45e0c2f20aed5e525ecda6a0b033e06da","head":{"label":"StasTelnov:com.epam.homework.task19","ref":"com.epam.homework.task19","sha":"84583dd45e0c2f20aed5e525ecda6a0b033e06da","user":{"login":"StasTelnov","id":3819003,"node_id":"MDQ6VXNlcjM4MTkwMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/3819003?v=4","gravatar_id":"","url":"https://api.github.com/users/StasTelnov","html_url":"https://github.com/StasTelnov","followers_url":"https://api.github.com/users/StasTelnov/followers","following_url":"https://api.github.com/users/StasTelnov/following{/other_user}","gists_url":"https://api.github.com/users/StasTelnov/gists{/gist_id}","starred_url":"https://api.github.com/users/StasTelnov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StasTelnov/subscriptions","organizations_url":"https://api.github.com/users/StasTelnov/orgs","repos_url":"https://api.github.com/users/StasTelnov/repos","events_url":"https://api.github.com/users/StasTelnov/events{/privacy}","received_events_url":"https://api.github.com/users/StasTelnov/received_events","type":"User","site_admin":false},"repo":{"id":129806282,"node_id":"MDEwOlJlcG9zaXRvcnkxMjk4MDYyODI=","name":"epam-core-04-2018","full_name":"StasTelnov/epam-core-04-2018","owner":{"login":"StasTelnov","id":3819003,"node_id":"MDQ6VXNlcjM4MTkwMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/3819003?v=4","gravatar_id":"","url":"https://api.github.com/users/StasTelnov","html_url":"https://github.com/StasTelnov","followers_url":"https://api.github.com/users/StasTelnov/followers","following_url":"https://api.github.com/users/StasTelnov/following{/other_user}","gists_url":"https://api.github.com/users/StasTelnov/gists{/gist_id}","starred_url":"https://api.github.com/users/StasTelnov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StasTelnov/subscriptions","organizations_url":"https://api.github.com/users/StasTelnov/orgs","repos_url":"https://api.github.com/users/StasTelnov/repos","events_url":"https://api.github.com/users/StasTelnov/events{/privacy}","received_events_url":"https://api.github.com/users/StasTelnov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/StasTelnov/epam-core-04-2018","description":null,"fork":true,"url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018","forks_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/forks","keys_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/keys{/key_id}","collaborators_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/teams","hooks_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/hooks","issue_events_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/issues/events{/number}","events_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/events","assignees_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/assignees{/user}","branches_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/branches{/branch}","tags_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/tags","blobs_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/git/refs{/sha}","trees_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/git/trees{/sha}","statuses_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/statuses/{sha}","languages_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/languages","stargazers_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/stargazers","contributors_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/contributors","subscribers_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/subscribers","subscription_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/subscription","commits_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/commits{/sha}","git_commits_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/git/commits{/sha}","comments_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/comments{/number}","issue_comment_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/issues/comments{/number}","contents_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/contents/{+path}","compare_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/compare/{base}...{head}","merges_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/merges","archive_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/downloads","issues_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/issues{/number}","pulls_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/pulls{/number}","milestones_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/milestones{/number}","notifications_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/labels{/name}","releases_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/releases{/id}","deployments_url":"https://api.github.com/repos/StasTelnov/epam-core-04-2018/deployments","created_at":"2018-04-16T21:11:39Z","updated_at":"2018-04-16T21:11:41Z","pushed_at":"2018-06-07T20:53:14Z","git_url":"git://github.com/StasTelnov/epam-core-04-2018.git","ssh_url":"git@github.com:StasTelnov/epam-core-04-2018.git","clone_url":"https://github.com/StasTelnov/epam-core-04-2018.git","svn_url":"https://github.com/StasTelnov/epam-core-04-2018","homepage":null,"size":86,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elefus:telnov","ref":"telnov","sha":"16a0969389e1bf1043d9605718f0ed4fd12f99c1","user":{"login":"elefus","id":15202315,"node_id":"MDQ6VXNlcjE1MjAyMzE1","avatar_url":"https://avatars1.githubusercontent.com/u/15202315?v=4","gravatar_id":"","url":"https://api.github.com/users/elefus","html_url":"https://github.com/elefus","followers_url":"https://api.github.com/users/elefus/followers","following_url":"https://api.github.com/users/elefus/following{/other_user}","gists_url":"https://api.github.com/users/elefus/gists{/gist_id}","starred_url":"https://api.github.com/users/elefus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elefus/subscriptions","organizations_url":"https://api.github.com/users/elefus/orgs","repos_url":"https://api.github.com/users/elefus/repos","events_url":"https://api.github.com/users/elefus/events{/privacy}","received_events_url":"https://api.github.com/users/elefus/received_events","type":"User","site_admin":false},"repo":{"id":129292076,"node_id":"MDEwOlJlcG9zaXRvcnkxMjkyOTIwNzY=","name":"epam-core-04-2018","full_name":"elefus/epam-core-04-2018","owner":{"login":"elefus","id":15202315,"node_id":"MDQ6VXNlcjE1MjAyMzE1","avatar_url":"https://avatars1.githubusercontent.com/u/15202315?v=4","gravatar_id":"","url":"https://api.github.com/users/elefus","html_url":"https://github.com/elefus","followers_url":"https://api.github.com/users/elefus/followers","following_url":"https://api.github.com/users/elefus/following{/other_user}","gists_url":"https://api.github.com/users/elefus/gists{/gist_id}","starred_url":"https://api.github.com/users/elefus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elefus/subscriptions","organizations_url":"https://api.github.com/users/elefus/orgs","repos_url":"https://api.github.com/users/elefus/repos","events_url":"https://api.github.com/users/elefus/events{/privacy}","received_events_url":"https://api.github.com/users/elefus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/elefus/epam-core-04-2018","description":null,"fork":false,"url":"https://api.github.com/repos/elefus/epam-core-04-2018","forks_url":"https://api.github.com/repos/elefus/epam-core-04-2018/forks","keys_url":"https://api.github.com/repos/elefus/epam-core-04-2018/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elefus/epam-core-04-2018/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elefus/epam-core-04-2018/teams","hooks_url":"https://api.github.com/repos/elefus/epam-core-04-2018/hooks","issue_events_url":"https://api.github.com/repos/elefus/epam-core-04-2018/issues/events{/number}","events_url":"https://api.github.com/repos/elefus/epam-core-04-2018/events","assignees_url":"https://api.github.com/repos/elefus/epam-core-04-2018/assignees{/user}","branches_url":"https://api.github.com/repos/elefus/epam-core-04-2018/branches{/branch}","tags_url":"https://api.github.com/repos/elefus/epam-core-04-2018/tags","blobs_url":"https://api.github.com/repos/elefus/epam-core-04-2018/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elefus/epam-core-04-2018/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elefus/epam-core-04-2018/git/refs{/sha}","trees_url":"https://api.github.com/repos/elefus/epam-core-04-2018/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elefus/epam-core-04-2018/statuses/{sha}","languages_url":"https://api.github.com/repos/elefus/epam-core-04-2018/languages","stargazers_url":"https://api.github.com/repos/elefus/epam-core-04-2018/stargazers","contributors_url":"https://api.github.com/repos/elefus/epam-core-04-2018/contributors","subscribers_url":"https://api.github.com/repos/elefus/epam-core-04-2018/subscribers","subscription_url":"https://api.github.com/repos/elefus/epam-core-04-2018/subscription","commits_url":"https://api.github.com/repos/elefus/epam-core-04-2018/commits{/sha}","git_commits_url":"https://api.github.com/repos/elefus/epam-core-04-2018/git/commits{/sha}","comments_url":"https://api.github.com/repos/elefus/epam-core-04-2018/comments{/number}","issue_comment_url":"https://api.github.com/repos/elefus/epam-core-04-2018/issues/comments{/number}","contents_url":"https://api.github.com/repos/elefus/epam-core-04-2018/contents/{+path}","compare_url":"https://api.github.com/repos/elefus/epam-core-04-2018/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elefus/epam-core-04-2018/merges","archive_url":"https://api.github.com/repos/elefus/epam-core-04-2018/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elefus/epam-core-04-2018/downloads","issues_url":"https://api.github.com/repos/elefus/epam-core-04-2018/issues{/number}","pulls_url":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls{/number}","milestones_url":"https://api.github.com/repos/elefus/epam-core-04-2018/milestones{/number}","notifications_url":"https://api.github.com/repos/elefus/epam-core-04-2018/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elefus/epam-core-04-2018/labels{/name}","releases_url":"https://api.github.com/repos/elefus/epam-core-04-2018/releases{/id}","deployments_url":"https://api.github.com/repos/elefus/epam-core-04-2018/deployments","created_at":"2018-04-12T18:03:26Z","updated_at":"2018-04-23T12:29:36Z","pushed_at":"2018-06-09T22:44:48Z","git_url":"git://github.com/elefus/epam-core-04-2018.git","ssh_url":"git@github.com:elefus/epam-core-04-2018.git","clone_url":"https://github.com/elefus/epam-core-04-2018.git","svn_url":"https://github.com/elefus/epam-core-04-2018","homepage":null,"size":1247,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"archived":false,"open_issues_count":46,"license":null,"forks":28,"open_issues":46,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394"},"html":{"href":"https://github.com/elefus/epam-core-04-2018/pull/394"},"issue":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/issues/394"},"comments":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/issues/394/comments"},"review_comments":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394/comments"},"review_comment":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/pulls/394/commits"},"statuses":{"href":"https://api.github.com/repos/elefus/epam-core-04-2018/statuses/84583dd45e0c2f20aed5e525ecda6a0b033e06da"}},"author_association":"NONE"}}
{"actor":{"display_login":"Ilya21"}}