Truth and Dare:
Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types:
• Truth task: Ram has to truthfully answer a question.
• Dare task: Ram has to perform a given task.
Each task is described by an integer. (If a truth task and a dare task are described by the same integer, they are still different tasks.) You are given four lists of tasks:
•Tr1T2Trtr the truth tasks Ram can perform.
•Dr.1.Dr.2, Dr.dr: the dare tasks Ram can perform.
Ts,1,Ts,2,..., Ts,ts: the truth tasks Shyam can ask Ram to perform.
Ds,1,Ds,2,..., Ds,ds: the dare tasks Shyam can ask Ram to perform.
Note that the elements of these lists are not necessarily distinct, each task may be repeated any number of times in each list.
Shyam wins the game if he can find a task Ram cannot perform. Ram wins if he performs all tasks Shyam asks him to. Find the winner of the game.
Let's take an example where Ram can perform truth tasks 3, 2 and 5 and dare tasks 2 and 100, and Shyam can give him truth tasks 2 and 3 and a dare task 100. We can see that whichever truth or dare tasks Shyam asks Ram to perform, Ram can easily perform them, so he wins. However, if Shyam can give him dare tasks 3 and 100, then Ram will not be able to perform dare task 3, so Shyam wins.
Input
• The first line contains a single integer tr.
• The second line contains t, space-separated integers Tr,1,Tr,2,...,Tr,tr
The third line contains a single integer dɲ.
• The fourth line contains d, space-separated integers Dr,1,D,2,..., Dr.dr.
• The fifth line contains a single integer ts.
The sixth line contains ts space-separated
integers Ts,1,Ts,2,...,Ts,ts
• The seventh line contains a single integer ds.
The eighth line contains ds space-separated integers Ds,1,Ds,2,..., Ds,ds
Output
For each test case, print a single line containing the string "yes" if Ram wins the game or "no" otherwise.
Constraints
• 1 tr,dr,ts,ds≤100
• 1 Tri≤100 for each valid i
• 1≤Dri≤100 for each valid i
• 1 Ts,i≤100 for each valid i
• 1≤Ds,i≤100 for each valid i
Example
Input 1:
2
1 2
3
1 3 2
1
2
2
3 2
Output 1:
yes
Explanation:
Ram's truth tasks are [1,2 ]and his dare tasks are [1,3,2]. Shyam's truth tasks are [2] and his dare tasks are [3,2]. Ram can perform all tasks Shyam gives him.
Input 2:
2
1 2
3
1 3 2
1
2
3
3 2 4
Output2:
no
Explanation:
Ram's truth tasks are [1,2] and his dare tasks are [1,3,2]. Shyam's truth tasks are [2] and his dare tasks are [3,2,4]. If Shyam asks Ram to perform dare task 4, Ram will not be able to do it.
Sample input
2
1 2
3
1 3 2
1
2
2
3 2
Sample output
yes
Program:
#C
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main() {
int tr, dr, ts, ds;
int Tr[MAX], Dr[MAX], Ts[MAX], Ds[MAX];
// read input values
scanf("%d", &tr);
for (int i = 0; i < tr; i++) {
scanf("%d", &Tr[i]);
}
scanf("%d", &dr);
for (int i = 0; i < dr; i++) {
scanf("%d", &Dr[i]);
}
scanf("%d", &ts);
for (int i = 0; i < ts; i++) {
scanf("%d", &Ts[i]);
}
scanf("%d", &ds);
for (int i = 0; i < ds; i++) {
scanf("%d", &Ds[i]);
}
// create sets for Ram's and Shyam's tasks
int ram_tasks[MAX], shyam_tasks[MAX];
int ram_tasks_size = 0, shyam_tasks_size = 0;
// add Ram's tasks to the set
for (int i = 0; i < tr; i++) {
ram_tasks[ram_tasks_size++] = Tr[i];
}
for (int i = 0; i < dr; i++) {
ram_tasks[ram_tasks_size++] = Dr[i];
}
// add Shyam's tasks to the set
for (int i = 0; i < ts; i++) {
shyam_tasks[shyam_tasks_size++] = Ts[i];
}
for (int i = 0; i < ds; i++) {
shyam_tasks[shyam_tasks_size++] = Ds[i];
}
// check if there is any task in Shyam's set that is not in Ram's set
for (int i = 0; i < shyam_tasks_size; i++) {
int found = 0;
for (int j = 0; j < ram_tasks_size; j++) {
if (shyam_tasks[i] == ram_tasks[j]) {
found = 1;
break;
}
}
if (!found) {
printf("no\n");
return 0;
}
}
printf("yes\n");
return 0;
}
0 Comments