Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
'A' and his friend 'B' are addicted to the game called "Level Up Game", which consists of n levels. Both want to clear the entire game.

'A' can clear only x number of levels of the game. And 'B' can clear only y number of levels of the game. Given the levels 'A' can clear and the levels 'B' can clear, can 'A' and 'B' clear the entire game if they work together?

Input Format

Starting line consists of single integer n. The following line contains an integer x as the first integer, then follows x distinct integers m1, m2, ..., mx. These integers denote the levels 'A' can clear. The third line consists the levels 'B' can clear in the same format as the second line, assuming that the levels are numbered 1 to n.

Constraints

n (1 ≤  n ≤ 100)

x (0 ≤ x ≤ n)

(1 ≤ mi ≤ n)

Output Format

If they can clear all the levels, print "GAME CLEARED". If it's impossible, print "GAME NOT CLEARED" (without the quotes).

Sample Input 0

4
3 1 2 3
2 2 4
Sample Output 0

GAME CLEARED


What I have tried:

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[] ) throws Exception {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
   Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int x=s.nextInt();
        int y=s.nextInt();
        int[] arr1 = new int[x]; 
        int[] arr2 = new int[y];
        
        
    
    }
}
Posted
Updated 16-Jun-22 21:37pm

Quote:
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int x=s.nextInt();
int y=s.nextInt();//<== this is wrong

The marked line is wrong: after reading x you should create the arr1 and fill it with the provided x values; afterwards you can read y (and then create arr2 and fill it with the provided values).

That said, a simple traverse of both the x and y arrays should do the trick (hint: use a Set).
 
Share this answer
 
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900