Trong phần này mình không được dùng dùng 1 số đặc biệt hay ký tự nào để cho hàm if break cái vòng lặp ra cả. Thường ở một số bài nhập dữ liệu cho mảng không biết trước số phần tử mình hay dùng:
if(a[i]==-1)
break;
Đại khái thế, nhưng mà ở vấn đề mình gặp đây thì yêu cầu là không cho mình nhập ký tự khác.Mình thì văn không giỏi nên nói không biết mấy bạn hiểu không nữa. Mấy bạn có thể đọc đề ở dưới nha.
There is a game called “I Wanna Be the Guy”, consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input
The first line contains a single integer n (1 ≤ n ≤ 100).The next line contains an integer p (0 ≤ p ≤ n) at first, then follows p distinct integers a1, a2, …, ap (1 ≤ ai ≤ n). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It’s assumed that levels are numbered from 1 to n.
Output
If they can pass all the levels, print “I become the guy.”. If it’s impossible, print “Oh, my keyboard!” (without the quotes).Ví dụ:
Input:
4
3 1 2 3
2 2 4Output: I become the guy.
Hoặc
Input:
10
5 8 6 1 5 4
6 1 3 2 9 4 6
Output: Oh, my keyboard!
Đây là đoạn code của mình, Ý tưởng thì mình dùng indexing để đếm, chỉ còn vướng mắc 1 chỗ về nhập phần tử
#include <iostream>
//I Wanna Be the Guy
using namespace std;
int c[1000];
int main()
{
int n;
cin >> n;
int a[n],b[n-1];
for(int i=0; i<n; i++)
cin >> a[i];
for(int i=0; i<n-1; i++)
cin >> b[i];
for(int i=0; i<n; i++)
c[a[i]]++;
for(int i=0; i<n-1; i++)
c[b[i]]++;
for(int i=1; i<=n; i++)
if(c[i]==0)
{
cout << "Oh, my keyboard!";
return 0;
}
cout << "I become the guy.";
return 0;
}