程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Blue Bridge Cup algorithm problem -- from entry to proficiency, 30 days of intensive practical training | CSDN original

編輯:Python
[ Introduction to programming ] Temperature conversion
Enter a Fahrenheit temperature , The output temperature in Celsius is required . Formula for c=5(F-32)/9, Take position 2 decimal .
A Fahrenheit temperature , Floating point numbers
F=float(input())
c=(5*(F-32)/9)
c="%.2f"%c
print("c="+c)
Three integers a b c, Input by keyboard , Output the maximum number .
Input
One row array , Respectively a b c
Output
a b c The largest number
a,b,c=map(int,input().split())
print(max(a,b,c))
There is a function
y={
 x x<1
| 2x-1 1<=x<10
{
 3x-11 x>=10
Write a program , Input x, Output y
x=int(input())
if x<1:
y=x
print(y)
elif x<10 and x>=1:
y=2*x-1
print(y)
elif x>=10:
y=3*x-11
print(y)
Give a 100 point mark , Output grade is required ‘A’、‘B’、‘C’、‘D’、‘E’. 90 Points and 90 The above points are A,80-89 It is divided into B,70-79 It is divided into C,60-69 It is divided into D,60 It is divided into the following E.
Input
An integer 0-100 within
A character , Indicates the grade
x=int(input())
if x>=0 and x<=100:
if x>=90 and x<=100:
print("A")
elif x>=80:
print("B")
elif x>=70:
print("C")
elif x>=60:
print("D")
else:
print("E")
Give not more than one 5 An integer , requirement 1、 Find out how many digits it is 2、 Output each digit separately 3、 Output the numbers in reverse order , For example, the original number is 321, The output should be 123
Input
One is not greater than 5 Digit number
Output
Three elements first line digit The second line Each number separated by a space , Note that there is no space after the last number The third line Output this number in reverse order
x=str(input())
# if len(x)<=5:
# print(len(x))
# for i in range(len(x)):
# print(x[i],end=" ")
# print()
# # h=sorted(list(x),reverse=True) Sort the list 
# print(x[::-1])
The bonus paid by the enterprise is based on the profit commission . The profit is less than or equal to 100000 yuan , Bonus can be raised 10%;
Profit is higher than 100000 element , lower than 200000 element (100000<I≤200000) when , lower than 100000 Part of yuan by 10% Royalty , higher than 100000 Part of the yuan , It's a percentage 7.5%;
200000<I≤400000 when , lower than 200000 The yuan part is still deducted according to the above methods ,( The same below ), higher than 200000 Part of yuan by 5% Royalty ;
400000<I≤600000 Yuan time , higher than 400000 Part of yuan by 3% Royalty ;
600000<I≤1000000 when , higher than 600000 Part of yuan by 1.5% Royalty ;
I>1000000 when , exceed 1000000 Part of yuan by 1% Royalty . Input the profit of the month from the keyboard I, The total amount of bonus payable .
i=int(input())
if i<=100000:
x=i*0.1
elif i<=200000:
x=100000*0.1+(i-100000)*0.075
elif i<=400000:
x=100000*0.1+100000*0.075+(i-200000)*0.05
elif i<=600000:
x=100000*0.1+100000*0.075+200000*0.05+(i-400000)*0.03
elif i<=1000000:
x=100000*0.1+100000*0.075+200000*0.05+200000*0.03+(i-600000)*0.015
else:
x=100000*0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.015+(i-1000000)*0.01
print(int(x))
Enter two positive integers m and n, Find the greatest common divisor and the least common multiple .
Input
Two integers
Output
greatest common divisor , Minimum common multiple
m,n = map(int,input().split())
if m>n:
m,n = n,m
def GCD(m,n):
if n%m == 0:
return m
else:
return GCD(n%m,m)
miny = GCD(m,n)
print(miny,end=" ")
print(m*n//miny)
Enter a line of characters , Count out the English letters 、 Numbers 、 Number of spaces and other characters .
Input
One line of characters , Length not exceeding 200
Output
Statistics
sum=0
sum_one=0
sum_two=0
sum_three=0
x=str(input())
for i in x:
if len(x)<=200:
if (i>='a' and i<='z') or (i>='A' and i<='Z'):
sum+=1
elif (i<='9' and i>='0'):
sum_one+=1
elif (i==" "):
sum_two+=1
else:
sum_three+=1
print(sum,sum_one,sum_two,sum_three)
seek Sn=a+aa+aaa+…+aa…aaa( Yes n individual a) It's worth , among a It's a number , by 2. for example ,n=5 when =2+22+222+2222+22222,n Input by keyboard .
n=int(input())
s=0
Sn=0
for i in range(1,n+1):
s=s*10+2
Sn+=s
print(Sn)
seek Sn=1!+2!+3!+4!+5!+…+n! It's worth , among n It's a number (n No more than 20).
n=int(input())
sum=1
count=0
if n<=20:
for i in range(1,n+1):
sum=sum*i
count+=sum
print(count)
Find the sum of the following three numbers , Retain 2 Decimal place 1~a The sum of the 1~b Sum of squares of 1~c The reciprocal of and
a,b,c=map(int,input().split())
sum=0
count=0
sum_count=0
sum_counti=0
for i in range(1,a+1):
sum+=i
for j in range(1,b+1):
count+=j**2
for h in range(1,c+1):
sum_count+=1/h
sum_counti=sum+count+sum_count
print('%.2f' %(sum_counti))
Title Description
This is the first problem for test. Since all we know the ASCII code, your job is simple: Input numbers and output corresponding messages.
Input
The input will contain a list of positive integers separated by whitespaces(spaces, newlines, TABs). Please process to the end of file (EOF). The integers will be no less than 32.
Output
Output the corresponding message. Note there is NOT a newline character in the end of output.
num_list1=map(int,input().strip().split())
num_list2=map(int,input().strip().split())
for i in num_list1:
print(chr(i),end="")
for j in num_list2:
print(chr(j),end="")
Print out all " Narcissistic number ", So-called " Narcissistic number " A three digit number , The sum of each digit cube is equal to itself . for example :153 It's a narcissus number , because 153=1^3+5^3+3^3.
for i in range(100, 999):
num = str(i)
a = int(num[0])
b = int(num[1])
c = int(num[2])
if (pow(a, 3)+pow(b, 3)+pow(c, 3)) == i:
print(i)
Xiaoqiang has loved life science since childhood , He always wondered where the flowers, plants, birds and animals came from . finally , Xiao Qiang went to middle school , Touched the sacred noun - -DNA. It has a double helix structure . This makes a single-minded roach scratch his scalp ,“ If only I could draw it ” Xiaoqiang shouted . Please help him now
Input
Input contains multiple sets of test data . The first integer N(N <= 15), N Represents the number of groups , Each set of data contains two integers a, b.a Represents a unit of DNA Number of rows in the string ,a Is odd and
3 <= a <= 39.b Indicates the degree of repetition (1 <= b <= 20).
Output
Output DNA The shape of the , There is a blank line between each group of outputs .
k = eval(input()) # Enter a value for k, use k To control how many DNA
for kk in range(k):
m, n = map(int, input().split()) # m Indicates how many symbols there are in each line ,n How many DNA chain 
p = 0 # p Used to control X The location of 
for i in range(m * n - n + 1): # Loop control the number of lines and the output of each line 
ls = list(' ' * m) # The initialization list is m A space ,
if p == i % (m - 1): # When p The value of is equal to i%(m-1) Phase at the same time , Then the position in the list p and m-1-p To change the value of ’X’
ls[p] = 'X'
ls[m - p - 1] = 'X'
for s in ls: # Output the modified list in one row 
print(s, end='')
p += 1 # take p The value of the add 1, To correspond to the next line X The location of 
print() # Control line feed 
if p == m - 1: # When p==m-1 when , Back to 0 Output position of 
p = 0
print()
Consider including N Digit number K- Hexadecimal number . Define a number to be valid , If it K- The hexadecimal representation does not contain two consecutive 0.
Consider including N Digit number K- Hexadecimal number . Define a number to be valid , If it K- The hexadecimal representation does not contain two consecutive 0.
example :
1010230 It works 7 digit
1000198 Invalid
0001235 No 7 digit , It is 4 digit .
Given two numbers N and K, The calculation is required to include N The number of significant digits K- The total number of hexadecimal numbers .
hypothesis 2 <= K <= 10; 2 <= N; 4 <= N+K <= 18.
n=int(input())
k=int(input())
re=0
def loop(c,m):
global n,k,re
if c==1:
if m==0:
re+=k-1
else:
re+=k
elif c==n:
for i in range(1,k):
loop(c-1,i)
else:
if m==0:
for i in range(1,k):
loop(c-1,i)
else:
for i in range(0,k):
loop(c-1,i)
loop(n,1)
print(re)
A natural number is 8 Excepting 1, The resulting quotient is 8 Besides 1,
The second quotient will be 8 Except after 7, Finally, we get a quotient of a.
Also know that this natural number is 17 Excepting 4. The resulting quotient is 17 Excepting 15,
The final quotient is a Of 2 times .
Find this natural number .
t1 = 7 * 64 - 15 * 17 + 5
t2 = 34 * 17 - 64 * 8
a = int(t1 / t2)
# From the above solution ideas , The following calculation is obtained x Formula 
x = 17 * (2 * a * 17 + 15) + 4
print(x)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved