Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class IEEE {
- public static void main(String[] args) throws IOException {
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- int x,y;
- //method 1(using the 2d array);
- int board[][]=new int [1001][1001];
- //filling the board with pieces
- for(int i=0;i<n;i++){
- x=sc.nextInt();
- y=sc.nextInt();
- board[x][y]=1;
- }
- //_______end of the input________\\
- int sum =0;//number of attacks
- int counter=0;//number of pieces in every row
- //loop for the rows:
- for(int i=1;i<1001;i++){
- for(int j=1;j<1001;j++){
- if(board[i][j]==1)counter++;
- }
- sum+=(counter*(counter-1))/2;//adding the number of attack
- counter=0;//reset the value to zero to start a new row
- }
- //loop for the colums
- for(int i=1;i<1001;i++){
- for(int j=1;j<1001;j++){
- if(board[j][i]==1)counter++;
- }
- sum+=(counter*(counter-1))/2;
- counter=0;
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement