TORONTO KIDS COMPUTER CLUB | Markham Saturday 14:00 Java Homework 21.04.17.
19318
post-template-default,single,single-post,postid-19318,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Markham Saturday 14:00 Java Homework 21.04.17.

22 Apr Markham Saturday 14:00 Java Homework 21.04.17.

Question 1:
Thuc likes finding cyclic shifts of strings. A cyclic shift of a string is obtained by moving characters from the beginning of the string to the end of the string. We also consider a string to be a cyclic shift of itself. For example, the cyclic shifts of ABCDE are:
ABCDE, BCDEA, CDEAB, DEABC, and EABCD.
Given some text, T, and a string, S, determine if T contains a cyclic shift of S.

Input Specification
The input will consist of exactly two lines containing only uppercase letters. The first line will be the text T, and the second line will be the string S. Each line will contain at most 1000 characters.

Output Specification
Output yes if the text, T, contains a cyclic shift of the string, S. Otherwise, output no.

Sample Input 1
ABCCDEABAA
ABCDE

Output for Sample Input 1
yes

Explanation of Output for Sample Input 1
CDEAB is a cyclic shift of ABCDE and it is contained in the text ABCCDEABAA.

Sample Input 2
ABCDDEBCAB
ABA

Output for Sample Input 2
no

Explanation of Output for Sample Input 2
The cyclic shifts of ABA are ABA, BAA, and AAB. None of these shifts are contained in the text ABCDDEBCAB.

Question 2:
You will be given two arrays A and B of positive integers. The number of values in both the arrays will be the same say N. Your task is to find the maximum sum of products of their elements. Each element in A has to be multiplied with exactly one element in B and vice versa such that each element of both the arrays appears exactly once and the sum of product produced is maximum.

if A = {5,1,3,4,2} and B = {8,10,9,7,6} then a possible sum of product is 5*6 + 1*7 + 3*9 + 4*10 + 2*8.

Input Specification:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of three lines. The first line consists of N the size of the two arrays. In the next are line N space separated positive integers denoting the values in array A and in the third line are N space separated positive integers denoting the values in array B.

Output Specification:
Print the maximum possible sum of products of the elements for each test case in a new line.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i],B[i] ≤ 1000


Sample Input:
1
3
1 2 3
4 5 1

Sample Output:
24
No Comments

Sorry, the comment form is closed at this time.