Sort by

recency

|

390 Discussions

|

  • + 0 comments
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            
            Scanner scanner = new Scanner(System.in);
            
            Set<String> uNames = new HashSet<>();
            int count = scanner.nextInt();
            for (int ii = 0; ii < count; ii++) {
                String name1 = scanner.next();
                String name2 = scanner.next();
                // This is wrong in the problem statement for "Test case 5" where
                // (a,b) is the same as (b,a)
                // addressing this symmetry here
                if (!uNames.contains(name1.concat(" ").concat(name2))
                 && !uNames.contains(name2.concat(" ").concat(name1))) {
                    uNames.add(name1.concat(" ").concat(name2));    
                 }
                
                System.out.println(uNames.size());
            }
            
            scanner.close();
        }
    }
    
  • + 0 comments

    Test case #5 is incorrect tho

    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    public class Solution {
    
     public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            int t = s.nextInt();
            String [] pair_left = new String[t];
            String [] pair_right = new String[t];
            
            for (int i = 0; i < t; i++) {
                pair_left[i] = s.next();
                pair_right[i] = s.next();
            }
            
            Set<AbstractMap.SimpleEntry<String, String>> set = new HashSet<>();
    
            for (int i = 0; i < t; i++) {
                
                set.add(new AbstractMap.SimpleEntry<>(pair_left[i], pair_right[i]));
                System.out.println(set.size());
            }
       }
    }
    
  • + 1 comment

    The Solution for the Problem is

    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    public class Solution {
    
     public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            int t = s.nextInt();
            String [] pair_left = new String[t];
            String [] pair_right = new String[t];
            
            for (int i = 0; i < t; i++) {
                pair_left[i] = s.next();
                pair_right[i] = s.next();
            }
    
    //Write your code here
            HashSet<String> pairs = new HashSet<>();
            
            for(int i = 0 ; i < t; i++){
                String str = pair_left[i] + " " + pair_right[i];
                String rev = pair_right[i] + " " + pair_left[i];
                if(!pairs.contains(rev)){
                    pairs.add(str);
                }
                System.out.println(pairs.size());
            }
    
       }
    }
    
  • + 0 comments

    Test case #5 is wrong, At least it's conflicted with this problem's desc.

  • + 0 comments

    how solve this i failed from 1/6 test cases there is error show in test case 5 import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); String [] pair_left = new String[t]; String [] pair_right = new String[t];

        for (int i = 0; i < t; i++) {
            pair_left[i] = s.next();
            pair_right[i] = s.next();
        }
    

    // ... your previous code unchanged ... Set hashSet = new HashSet<>(); for (int i = 0; i < t; i++){ hashSet.add(pair_left[i]+" "+pair_right[i]);hoow System.out.println(hashSet.size()); } } }