第36期:IT培训-领先公司的当前问题和挑战

向您推出面试中新的任务选择。在上一篇文章中检查问题的解决方案



宣传片:在下一期中,我们将尝试一种新格式。为此,我们与一家公司合作-这是一家以IT部门闻名的最大零售商(评论中接受了猜测)。正如他们所说,请继续关注。该专栏由招聘机构Spice IT支持

我提醒您,本文的概述如下:我们发布了2个问题,不需要编写代码即可进行预热。接下来,我们发布3个任务,其中涉及以一种您方便的语言编写代码,除非在特定任务中另有指定。
而且,所有问题和任务的复杂性都在增加。
因此,让我们开始吧。

问题


1. 在Excel中查找丢失的行
我们提供了一个Excel工作表,其中包含1到50的整数,包括两者。但是,数字是混杂的形式,并且缺少1个整数。您必须编写代码来识别丢失的整数。仅逻辑是必需的。

传递
excel, 1 50 . , , . , .

2. 井字游戏
井字游戏是在两个玩家之间进行的,经过六步移动,游戏处于低于状态。

您能回答以下问题吗?
  • 谁会赢得比赛,O还是X?
  • 第六个标记在哪个位置?

假设两个玩家都足够聪明。

传递
- , ( ) .
?
  • , ?
  • 6- ?

, .

任务


1. 寻找Nim游戏的获胜者
In Game of Nim, two players take turns removing objects from heaps or the pile of stones.
Suppose two players A and B are playing the game. Each is allowed to take only one stone from the pile. The player who picks the last stone of the pile will win the game. Given N the number of stones in the pile, the task is to find the winner, if player A starts the game.

Input:
The input line contains T, denoting the number of test cases. Then T test case follows, a single line of the input containing a positive integer N.

Output:
Print the winner i.e. Player A or Player B for each testcase in a separate line.

Constraints:
1 <= T <= 100
1 <= N <= 1000


Example:
Input:

2
3
15


输出:说明:测试案例1:玩家A移除顶部的石头1,然后玩家B移除石头2 ,最后玩家A移除最后一块石头。
Player A
Player A





传递
Nim .
, . . , , . N , , , .

:
T, . N .

:
, B, .

:
1 < = T < = 100
1 < = N < = 1000


:
:

2
3
15


:



:
1: 1, , 2,
, , — .

2. 队列反转
Given a Queue Q containing N elements. The task is to reverse the Queue. Your task is to complete the function rev(), that reverses the N elements of the queue.

Input:
The first line of input contains an integer T denoting the Test cases. Then T test cases follow. The first line contains N which is the number of elements which will be reversed. Second line contains N space seperated elements.

Output:
For each testcase, in a new line, print the reversed queue.

Your Task:
This is a function problem. You only need to complete the function rev这需要一个队列作为参数和返回反队列印刷完成后自动驱动程序代码

约束:示例: 输入:说明:测试用例1:反转了队列的给定元素后,结果队列将为6 2 10 1 34。测试用例2:反转了队列的给定元素后,结果队列将为1 2 3 4。
1 ≤ T ≤ 100
1 ≤ N ≤ 105
1 ≤ elements of Queue ≤ 105




2
6
4 3 1 10 2 6
4
4 3 2 1
Output :

6 2 10 1 3 4
1 2 3 4





传递
Q, N . , . — rev(), N .

:
T, . T . N — , . N .

:
.

:
. rev, . .

:
1 ≤ T ≤ 100
1 ≤ N ≤ 105
1 ≤ ≤ 105


:
:

2
6
4 3 1 10 2 6
4
4 3 2 1

:
6 2 10 1 3 4
1 2 3 4


:
1: 6 2 10 1 3 4.
2: 1 2 3 4.

3. PriorityQueue上的操作
Given N integers, your task is to add these elements to the PriorityQueue. Also, given M integers, the task is to check if element is present in PriorityQueue. If present, print 1 and return the max element of priority queue, and then delete the max element. If not present, print -1.

Input Format:
First line of testcas contains number of testcases T. For each testcase, there will be 4 lines. First line contains N, number of elements to be inserted into the Priority Queue. Second line contains N positive integers separated by space. Third line contains M, fourth line contains M positive integers.

Output Format:
For each testcase, print «1» and max element in newlines if element to be found is present in the PriorityQueue, else print "-1".

Your Task:
Your task is to complete the functions insert(), find(), and delete(), such that it adds, find and delete the elements from the queue respectively.

Constraints:
1 <= T <= 100
1 <= N <= 103
1 <= M <= 103


Example:
Input:

1
8
1 2 3 4 5 2 3 1
5
1 3 2 9 10


Output:
1
5
1
4
1
3
-1
-1


Explanation:
Testcase 1: After inserting given elements, when we find 1, which is present, so we print 1, and then we print the top element of the PriorityQueue which is 5, and delete it. Similarly, when element is not present, just print "-1".

N , , PriorityQueue. , M , , , PriorityQueue. , 1 , . , -1.

:
. 4 . N — , . N , . MPriorityQueue, M .

:
«1» , PriorityQueue, "-1".

:
, insert(), find() delete() , , .

:
1 < = T < = 100
1 < = N < = 103
1 <= M < = 103


:
:

1
8
1 2 3 4 5 2 3 1
5
1 3 2 9 10


:
1
5
1
4
1
3
-1
-1


:
1: , PriorityQueue = 1 2 3 4 5 2 3 1. 1 3 2 9 10. «1» PriorityQueue, «1» PriorityQueue «5» . , , "-1".


1
, 1 n (n*(n+1)/2)
1 50
50*(50+1)/2 (, n = 50)
= 50*(51)/2
= 25*51
= 1275.

, , , , 1275. 1275 .

2
O . 9.
:
7- 5, X, O. , 6- , . – 6- 7, 9.

, , 6- 7. 5 .

, X, 9. . , .

1
printf("%s\n",(n % 2) ? "Player A" : "Player B");

2
{
    // add code here.
    stack<long long int> st;
    while(!q.empty())
    {
        int a=q.front();
        st.push(a);
        q.pop();
    }
    while(!st.empty())
    {
        q.push(st.top());
        st.pop();
    }
    return q;
}

3
static void insert(PriorityQueue<integer> q, int k){
q.add(k);
}

static boolean find(PriorityQueue<integer> q, int k){
return q.contains(k);
}

static int delete(PriorityQueue<integer> q){
int removed = q.remove();
return removed;
}

All Articles