
Вдохновлялись собеседованиями в американский Walmart. Ну что, готовы пошевелить извилинами?
Ответы на задачки из прошлого выпуска уже опубликованы. Сверяйтесь.
Вопросы
1. Fill the Jug
There are two empty jugs each of 4 and 3 liters respectively, without any measuring marks. How many minimum steps are required to have 2 liters of water into the 4 litre jug (the jugs can be filled any number of times with water, and they can be emptied any number of times).
2. Geek and Cashier
A Geek asks a cashier to pay Rs 200 for a cool program written by him. He asks the cashier to pay only in the following way:
- Few 1 Rs Notes. Let x.
- Few 2 Rs Notes. Must ten times of 1 Rs Notes, i.e., 10x.
- Rest of the money as 5 Rs Notes(Minimum number Rs 5 notes should be used)
How does the Geek’s Cashier plan to pay?
- Несколько банкнот по 1 Рупии. Пусть X.
- Несколько банкнот по 2 Рупии. Необходимо в десять раз больше, чем банкнот по 1 рупии, то есть 10х.
- Остальные деньги в виде банкнот по 5 рупий(минимальное количество банкнот по 5 рупий должно быть использовано)

Как собирается расплачиваться кассир?
Задачи
1. Reverse words in a given string
Given a String of length S, reverse the whole string without reversing the individual words in it. Words are separated by dots.
Input:
The first line contains T denoting the number of testcases. T testcases follow. Each case contains a string S containing characters.
Output:
For each test case, in a new line, output a single line containing the reversed String.
Constraints:
1 <= T <= 100
1 <= |S| <= 2000
Example:
Input:
2
i.like.this.program.very.much
pqr.mno
Output:
much.very.program.this.like.i
mno.pqr
Ввод:
Первая строка содержит T, обозначающее количество тестовых наборов. Каждый тест содержит строку S, содержащую символы.
Вывод:
Для каждого теста в новой строке выведите одну строку, содержащую перевернутую строку.
Ограничения:
1 <= T <= 100
1 <= |S| <= 2000Пример:
Ввод:
2
i.like.this.program.very.much
pqr.mnoВывод:
much.very.program.this.like.i
mno.pqr2. Kadane's Algorithm
Given an array arr of N integers. Find the contiguous sub-array with maximum sum.
Input:
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.
Output:
Print the maximum sum of the contiguous sub-array in a separate line for each test case.
Constraints:
1 ≤ T ≤ 110
1 ≤ N ≤ 106
-107 ≤ A[i] <= 107
Example:
Input
2
5
1 2 3 -2 5
4
-1 -2 -3 -4
Output
9
-1
Explanation:
Testcase 1: Max subarray sum is 9 of elements (1, 2, 3, -2, 5) which is a contiguous subarray.
Ввод:
Первая строка входных данных содержит целое число T, обозначающее количество тестов. Описание тестов t следующим образом. Первая строка каждого тестового набора содержит одно целое число N, обозначающее размер массива. Вторая строка содержит N целых чисел, разделенных пробелами A1, A2,..., Обозначающий элементы массива.
Вывод:
Выведите максимальную сумму смежного поддерева в отдельной строке для каждого теста.
Ограничения:
1 ≤ T ≤ 110
1 ≤ N ≤ 106
-107 ≤ A[i] <= 107Пример:
Ввод
2
5
1 2 3 -2 5
4
-1 -2 -3 -4Вывод
9
-1Объяснение:
Пример 1: максимальный подмассив — сумма 9 элементов (1, 2, 3, -2, 5) которая представляет собой непрерывный подмассив.
3. Ugly Numbers
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … shows the first 11 ugly numbers. By convention, 1 is included. Write a program to find Nth Ugly Number.
Input:
The first line of input contains an integer T denoting the number of test cases. T testcases follow. For each testcase there is one line of input that contains the number N.
Output:
Print the Nth Ugly Number.
Constraints:
1 ≤ T ≤ 104
1 ≤ N ≤ 104
Example:
Input:
2
10
4
Output:
12
4
Ввод:
Первая строка входных данных содержит целое число T, обозначающее количество тестов. Для каждого тестового набора существует одна строка ввода, содержащая число N.
Вывод:
Вывести N-нное по счёту «уродливое» число.
Ограничения:
1 ≤ T ≤ 104
1 ≤ N ≤ 104Пример:
Ввод:
2
10
4Вывод:
12
4Ответы
Объяснение:
Шаг 1: полностью наполните 3-литровый кувшин водой;
Шаг 2: перелейте воду из 3-литрового кувшина в 4-литровый;
Шаг 3: снова наполните 3-литровый кувшин водой полностью;
Шаг 4: налейте воду из 3-литрового кувшина в 4-литровый кувшин, пока 4-литровый кувшин не станет полным;
Шаг 5: вылейте воду из 4-литрового кувшина;
Шаг 6: Теперь у нас осталось 2 литра воды в 3-литровом кувшине. Перелейте воду из 3-литрового кувшина в 4-литровый кувшин, в результате чего в 4-литровом кувшине окажется 2 литра воды.
Самая маленькая сумма из 1 рупии и 2 рупий, которую может заплатить кассир, составляет 21 (1 банкнота размером в 1 рупию + 10 банкнот в 2 рупии). Таким образом, кассир должен платить кратно 21, чтобы удовлетворить первые два условия, а также сумма не должна превышать общую сумму в 200 рупий.
Кратные 21:
21, 42, 63, 84, 105, 126, 147 и 189.Из этого числа только 105 кратно 5. Поэтому он должен отдать остаток 95 рупий в 5-ти купюрах.

Ответ: кассир должен выдать 5 купюр по одной рупии, 50 купюр по две рупии и 19 купюр по пять рупий.
#include <iostream> #include<bits/stdc++.h> using namespace std; int main() { //code int t; cin >> t; while(t--){ string ip; cin >> ip; char s[ip.length()]; int i; for(i=0;i<ip.length();i++) s[i] = ip[i]; s[i]='\0'; char *c; vector<string> a; c = strtok(s,"."); while(c!=NULL){ a.push_back(c); c = strtok(NULL,"."); } for(int i=a.size()-1;i>=0;i--){ cout << a[i]; if(i!=0) cout << "."; } cout << endl; } return 0; }
#include <iostream> #include <stdlib.h> using namespace std; int kadane(int arr[], int size){ int curMax,gMax; curMax=arr[0]; gMax=arr[0]; for(int i=1;i<size;i++){ curMax=max(arr[i],curMax+arr[i]); gMax=max(curMax,gMax); } cout<<gMax<<"\n"; return 0; } int main() { int ntc , size, arr[100]; cin>>ntc; while(ntc--){ cin>>size; for(int i=0;i<size; i++) cin>>arr[i]; kadane(arr,size); } return 0; }
import java.util.*; import java.lang.*; import java.io.*; class GFG { static void Ugly(long a[]) { PriorityQueue<Long> pq= new PriorityQueue<>(); SortedSet<Long> set= new TreeSet<>(); long source =1; //Here we are using the same technique mentioned in hints // Using PriorityQueue to retrieve from all min values // Storing in SortedSet to avoid duplicacy //Note: to avoid further calculations we are calculating it till max test case value 10001 and just returning the arr index while(set.size()!=10001) { if(!pq.contains(source*2)) pq.add(source*2); if(!pq.contains(source*3)) pq.add(source*3); if(!pq.contains(source*5)) pq.add(source*5); set.add(source); source=pq.remove(); } int i=0; for(long l:set) { a[i]=l; i++; } } public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine().trim()); long[] arr= new long[10001]; Ugly(arr);// to Store ugly no. in an array for(int count =0;count<t;count++) { int num=Integer.parseInt(br.readLine().trim()); System.out.println(arr[num-1]); } } }

