1. Calculate the height of multiple landing balls
Title Description
A ball falls freely from a height of 100 meters, bounces back half its original height after each fall, then falls and bounces again. How many meters did it pass and how high did it bounce from the first time it landed to the N th time it landed?
input
A positive integer N representing the number of times the ball has fallen.
output
length = the distance the ball traveled on its N th landing
high = the height of the ball's N th bounce off the ground
Keep 4 decimal places after the decimal point.
Note: End output wraps.
sample input
10
sample output
length=199.8047 high=0.
Ideas: Examine the knowledge reserved by decimals, and note that the output is the distance to the ground
count = int(input()) hign = 100 res = 100 for i in range(count): hign = hign/2 res = res+hign res = res -hign print('length=%.4f' %res) print('high=%.4f' %hign)
2. Integer parity ordering
Title Description
Enter 10 integers separated by spaces. After reordering, the output (also separated by spaces) requires:
1. Output the odd numbers first and arrange them from large to small;
2. Then output the even numbers and arrange them from smallest to largest. **
input
Arbitrarily ordered 10 integers (0-100), separated by spaces.
output
There may be multiple sets of test data. For each set of data, the output is sorted as required and separated by spaces.
sample input
0 56 19 81 59 48 35 90 83 75 17 86 71 51 30 1 9 36 14 16
sample output
83 81 75 59 35 19 0 48 56 90 71 51 17 9 1 14 16 30 36 86
Tips
Multiple sets of data, note the output format
1. There may be many groups of test data, please use while(cin>>a[0]>>a[1]>>...>>a[9])Do a similar thing; 2. The input data is random and may be equal.
Ideas: Lists are continuously sorted and stitched, and note that input data is split by map(int,input().split(')) and input data is split by spaces
while True: a,b,c,d,e,f,g,h,i,j=map(int,input().split()) list= [] list.append(a) list.append(b) list.append(c) list.append(d) list.append(e) list.append(f) list.append(g) list.append(h) list.append(i) list.append(j) list_qishu = [] list_oushu = [] lengh = len(list) for i in range(lengh): if list[i]%2 == 0: list_oushu.append(list[i]) else: list_qishu.append(list[i]) #print(list_qishu.sort(key=lambda x:x[0], reverse=False)) list1=[] list_qishu1 = sorted(list_qishu, key=None, reverse=True) list_oushu1 = sorted(list_oushu, key=None, reverse=False) for i in range(len(list_qishu1)): print(list_qishu1[i],end=' ') for x in range(len(list_oushu1)): print(list_oushu1[x],end=' ') print()
3. Decryption
Title Description
Little F lives in Hampu school district. He wants to chat with his classmate Little L in Dongtang school district. To ensure the communication security, he invented an encryption method. This
The encryption method is as follows: For a 01 string, Little F divides it into groups of 8 bits from left to right, and the last group may be less than 8 bits.
Reverse the order of each group, that is, if it was bL bL+1bL+2 /. bR_1bR, then it became bR bR_1bR_2 /. bL_1bL. Now?
Little F has encrypted a string and sent it to little L. Can you help little L get the original information corresponding to this string of ciphers?
input
Single set of data.
One line is a 01 string, representing an encrypted string with a length greater than 0 and less than or equal to 100.
output
A line of string representing the original message corresponding to the encrypted string.
sample input
100010110011101
sample output
110100011011100
Idea: Pay attention to multiple lines of input, single set of data!= Single set of inputs, using for line in sys.stdin, note the end processing of the string
import sys for line in sys.stdin: #Prevent trailing whitespace from str_a = line.strip() str_a = line.split()[0] list_a = [] length = len(str_a) count = 0 for i in range(length): count+=1 list_a.append(str_a[i]) #Output string after reverse order if length is 8 or if last element has been traversed if count==8 or i == length-1: count = 0 list_a.reverse() print(''.join(list_a),end='') list_a = [] print("")
4. Lost cows
Title Description
Niu Niu went to the teacher's home to make up for his lessons. He was facing the north when he left, but now he was lost. Although he has a map in his hand, he needs to know which direction he is facing. Please help him.
input
Each input contains a test case. The first line of each test case contains a positive integer indicating the number of times the direction was turned N(N<=1000). The next line contains a length of N The string of the L and R Form, L Turn left, R Indicates turning right.
output
The direction the cow faces last, N North, S South, E East, W Represents West.
sample input
3 LRR
sample output
E
Ideas: Pay attention to controlling the input, such as str_a[0:count], otherwise it will not pass
count = int(input()) str_a = input() str_a = str_a[0:count] res = 0 #Judging initial direction if str_a[0] == 'L': res = 4 else: res = 2 for everyChar in str_a[1:] : #Add 1 to the right, subtract 1 from the left if everyChar == 'R': res +=1 #At this point the direction is North if (res == 5): res = 1 else: res-=1 # At this point the direction is West if (res == 0): res = 4 if((res == 1)): print('N') if(res == 2) : print('E') if(res == 3) : print('S') if(res == 4) : print('W')
5. Cool Words
Title Description
Enter words that consist of only lowercase letters. Your task is to count how many words are "cool", that is, how many times each letter appears.
For example, a d A is cool because a occurs twice, d occurs once, and 1 and 2 are different. banana is cool, for example, because a occurs three times, n twice, and b once. However, bbacccd is not cool because a and d occur the same number of times (once each).
input
The input contains no more than 30 sets of data. The number of words in the first behavior of each group of data is n (1<=n<=10000). The following N lines contain one word each, with letters ranging from 1 to 30.
output
For each set of data, output the test point number and the number of cool words.
sample input
2 ada bbacccd 2 illness a
sample output
Case 1: 1 Case 2: 0
Ideas: Mainly investigate python's dictionary knowledge and the use of set function
t=1 while True: count_a = 0 count = int(input()) count1 = count list_a = [] while count>0: list_a.append(input()) count-=1 char_dict = {} for i in range(count1): for x in range(len(list_a[i])): count2 = list_a[i].count(list_a[i][x]) char_dict[list_a[i][x]] = count2 # Data is deduplicated if the element in the list is greater than 1 after deduplication length_a = len(set(char_dict.values())) #If the number of elements is equal to the original number after weight removal, the word is cool if length_a == len(char_dict) and len(list_a[i]) != 1: count_a += 1 #Not a cool word else: pass char_dict = {} print('Case {0}: {1}'.format(t,count_a)) t+=1