(小鲤鱼加油站5)(H)O - Playing With Strings(未补代码)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BHliuhan/article/details/82190424
     **H**

Dani and Mike are two kids ,They are playing games all day and when they don’t find a game to play they invent a game . There is about an hour to arrive to school, because they love playing with strings Dani invented a game , Given a string and the winner is the first who form a palindrome string using all letters of this string according to the following sample rules : 1- player can rearrange letters to form a string . 2- the formed string must be palindrome and use all letters of the given string. 3- if there is more than one string chose the lexicographically smallest string . EX: string is “abacb” player can form : “abcba” and “bacab” ,but “abcba” is the lexicographically smallest. Mike asked you to write a Program to compute the palindrome string so he can beat Dani.

Input
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1  ≤  T  ≤  1000). Every test case on one line contain one string ,the length of the string will not exceed 1000 lower case English letter.

Output
For each test case print a single line containing the lexicographically smallest palindrome string according to the rules above. If there is no such string print “impossible”

Examples
Input
4
abacb
acmicpc
aabaab
bsbttxs
Output
abcba
impossible
aabbaa
bstxtsb
Note
Palindrome string is a string which reads the same backward or forward.

Lexicographic order means that the strings are arranged in the way as they appear in a dictionary.
思路:
先统计每个字符出现的次数,然后如果奇数个大于1个就不对;否则,按照字典序进行输出,先输出每个字符数目的一半,然后对有没有奇数个进行判断,如果有奇数个就把这个奇数个标记一下,在输出完前一半之后输出这一个奇数对应的字符,之后再输出后一半;

F
Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a is ‘good’ if it has a substring which is equal to b. However, a is ‘almost good’ if by inserting a single letter inside of it, it would become ‘good’. For example, if a = ‘start’ and b = ‘tear’: b is not found inside of a, so it is not ‘good’, but if we inserted the letter ‘e’ inside of a, it will become ‘good’ (‘steart’), so a is ‘almost good’ in this case. Your task is to determine whether the word a is ‘good’ or ‘almost good’ or neither.

Input
The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. Each of the following T lines represents a test case and contains two space separated strings a and b, each of them consists of lower case English letters. It is guaranteed that the length of a is between 4 and 1000, and the length of b is exactly 4.

Output
For each test case, you should output one line: if a is ‘good’ print ‘good’, if a is ‘almost good’ print ‘almost good’, otherwise print ‘none’.

Example
Input
4
smart mark
start tear
abracadabra crab
testyourcode your
Output
almost good
almost good
none
good
Note
A substring of string s is another string t that occurs in s. Let’s say we have a string s = “abcdefg” Possible valid substrings: “a”,”b”,”d”,”g”,”cde”,”abcdefg”. Possible invalid substrings: “k”,”ac”,”bcef”,”dh”.
思路:先在第一个字符串中找第二个字符串,看看能不能找到,能找到就输出good,不然,再继续找,找第二个字符串的子串,有4个长度为3的子串,在第一个里面如果能找到其中一个就输出almost good

E

ACM-SCPC-2017 is approaching every university is trying to do its best in order to be the Champion, there are n universities, the ith of them has exactly ai contestants. No one knows what is the official number of contestants in each team yet, this year organizers are planing to minimize number of teams participating in the contest but they still want every contestant to participate, so they should select a number k so that each team will consist of exactly k contestant from the same university. Every contestant will belong to one team exactly, and number of these teams is as minimum as possible. Your job is to help the organizers in their task by writing a program that calculates two integers k, the number of contestants in each team, and m, the minimum number of teams will participate. 1 ≤ n ≤ 1000, 1 ≤ ai ≤ 106

Input
First line of input contains an integer T denotes number of test cases. Each test case contains two lines: the first line contains one integer n denotes number of universities, while the second line contains n space-separated integers the ith of them denotes number of contestants from the ith university.

Output
For each test case, print one line containing two integers: the first one is k, the size of each team, and the second one is m, the minimum number of teams from all universities according to the previous conditions.

Example
Input
2
3
5 15 10
4
4 6 8 12
Output
5 6
2 15
思路:
找这几个数的最大公约数;找到后用总和除以这个数;

C
Statements
Rami went back from school and he had an easy homework about bitwise operations (and,or,..) The homework was like this : You have an equation : ” A | B = C ” ( this bar ‘|’ means OR ) you are given the value of A and B , you need to find the value of C ?? as we said before this is an easy question for Rami to solve ,but he wonderd if the equation was like this: ” A | C = B ” and he is given the value of A and B , how many value of C exists ?? Rami wants your help in this hard question … He will help you as much as he can ,so he will convert the two decimal numbers(A and B) to binary representaion ( like this: if A=6 –> A=110 ) and this what he knows about OR operation and might be helpfull with your task :

Input
The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. each test case consists of 3 lines : the 1st line is the length of the binary representaion of the 2 numbers.1<=n<=100 the 2nd line is the number A in base 2 .(a string consits of 0s and 1s only ) the 3rd line is the number B in base 2 .(a string consits of 0s and 1s only )

Output
for each test case,you need to print the number of possible values of C that make the eqaution correct in a seperate line .(read page 2 carefully)

Example
Input
3
2
10
11
3
110
110
4
1110
1011
Output
2
4
IMPOSSIBLE
Note
as the answer may be very very large , you should print the answer mod 1000000007. there might be no answer for the equation also , in this case you should print “IMPOSSIBLE” (without qoutes).
思路:根据上面的运算可以知道,如果A对应位上是1,B对应位上是0,这种直接不对,A为1,B为1,有2种情况,A为0,B为1,1种情况,A为0,B为0只有一种情况;所以进行枚举比较,定义一个累乘变量;注意要取模10000000007,并且累乘变量每次变化之后都要取模1000000007;最后也要取模10000000007;
B
Statements
A group of junior programmers are attending an advanced programming camp, where they learn very difficult algorithms and programming techniques! Near the center in which the camp is held, is a professional bakery which makes tasty pastries and pizza. It is called ‘Bonabity’… or ‘Ponapety’… or ‘Ponabity’… Actually no one knows how to spell this name in English, even the bakery owner doesn’t, and the legends say that Arabs always confuse between ‘b’ and ‘p’, and also between ‘i’ and ‘e’, so ‘b’ for them is just the same as ‘p’, and ‘i’ for them is just the same as ‘e’, they also don’t care about letters’ cases (uppercase and lowercase for a certain letter are similar). For example, the words ‘Ponabity’ and ‘bonabety’ are considered the same. You are given two words including only upper case and lower case English letters, and you have to determine whether the two words are similar in Arabic.

Input
The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. Each of the following T lines represents a test case and contains two space-separated strings (each one consists of only upper case and lower case English letters and its length will not exceed 100 characters).

Output
For each test case print a single line: ‘Yes’ if the words are similar in Arabic and ‘No’ otherwise.

Example
Input
4
Ponabity bonabety
barbie barpee
abcabc apcap
abc apcd
Output
Yes
Yes
No
No
思路:
先把每个字符串里面的p,P,B都变成b,把I,i,E都变成e,然后进行比较:不要忘了,ABC,abc是相等的,所以要把字符串里面的大写都变成小写之后两个字符串再进行比较

猜你喜欢

转载自blog.csdn.net/BHliuhan/article/details/82190424