القضية رقم 36: التدريب على تكنولوجيا المعلومات - القضايا والتحديات الحالية من الشركات الرائدة

عرضت عليك مجموعة جديدة من المهام من المقابلات. تحقق من حلولك لمشاكل المقالة السابقة - هنا.



دعابة: في العدد القادم سنحاول تنسيق جديد. لقد دخلنا في شراكة مع شركة واحدة - أكبر بائع تجزئة معروف بقسم تكنولوجيا المعلومات (التخمينات مقبولة في التعليقات). ترقبوا ، كما يقولون. العمود مدعوم من قبل وكالة التوظيف Spice IT .

أذكركم أن الخطوط العريضة لمقالنا هذا - نحن ننشر سؤالين لا يتطلبان كتابة كود للتدفئة. بعد ذلك ، ننشر 3 مهام تتضمن كتابة التعليمات البرمجية بإحدى اللغات المناسبة لك ، ما لم يتم تحديد خلاف ذلك في مهمة معينة.
أيضا ، كل الأسئلة والمهام تذهب في ترتيب متزايد من التعقيد.
لذلك دعونا نبدأ.

الأسئلة


1. البحث عن الصف المفقود في Excel
لدينا ورقة اكسل تحتوي على أعداد صحيحة من 1 إلى 50 ، بما في ذلك كليهما. ومع ذلك ، فإن الأرقام في شكل مختلط وهناك عدد صحيح مفقود. يجب عليك كتابة رمز لتحديد العدد الصحيح المفقود. المنطق مطلوب فقط.

نقل
excel, 1 50 . , , . , .

2. تيك تاك تو اللغز
يتم لعب لعبة Tic-Tac-Toe بين لاعبين وهي في حالة أقل بعد ست حركات.

هل يمكن أن تجيب على الأسئلة التالية؟
  • من سيفوز باللعبة ، O أو X؟
  • التي كانت العلامة السادسة وفي أي موقف؟

افترض أن كلا اللاعبين أذكياء بما فيه الكفاية.

نقل
- , ( ) .
?
  • , ?
  • 6- ?

, .

مهام


1. البحث عن الفائز في لعبة نيم
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


الإخراج: شرح: Testcase 1: اللاعب A إزالة الحجر 1 الموجود في الأعلى ، ثم Player 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أن يأخذ طابور كمعلمة و يعود في طابور عكس . و الطباعة ويتم تلقائيا من قبل رمز السائق .

المعوقات: مثال: الإدخال: الشرح: Testcase 1: بعد عكس عناصر قائمة الانتظار المحددة ، ستكون قائمة الانتظار الناتجة 6 2 10 1 3 4. Testcase 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