当前位置:网站首页>7-7 7003 combination lock (PTA program design)
7-7 7003 combination lock (PTA program design)
2022-07-06 13:56:00 【Programming Lindaiyu】
Now school begins on a weekday . Their dormitory is locked with a password ( See figure ) lock . He knows that the password is three logarithm , Such as 36-23-12, At the same time, know the method of unlocking . Its method :
(1) First turn clockwise for two turns .
(2) Turn counterclockwise to the position of the first number .
(3) Turn counterclockwise .
(4) Rotate clockwise to the second number .
(5) The pointer turns counterclockwise to the third number .
Know the initial position and password of the pointer , Ask how many degrees to unlock .

Input format :
There are multiple sets of data , Each group of data contains four numbers , Namely n,fisrt,middle,last, Are less than 40(n Is the starting position ) Greater than 0 Of . When the input is “0 0 0 0” when , end .
Output format :
Output the degree of rotation .
sample input :
0 30 0 30
5 35 5 35
0 20 0 20
7 27 7 27
0 10 0 10
9 19 9 19
0 0 0 0
sample output :
1350
1350
1620
1620
1890
1890
Code (Python):
d=[] # A list for storing results
n,first,middle,last=map(int,input().split())
def func(first,last): # Set function , Used to calculate degrees
if first<=last: # There are two cases , If the initial position is small , Normal minus
return (last-first)*9 #9 Is the degree represented by each scale
else: # If the initial position is large , It means that I passed 0 scale , You can't reduce it directly
return (40-first+last)*9 # First use 40 Subtract the end scale , Plus the initial scale is the total scale , multiply 9 Convert to degrees
while 1:
if n==0 and first==0 and middle==0 and last==0: # When the input is “0 0 0 0” when , end
break
else: # Otherwise, the input is not “0 0 0 0” when , Start calculating
res=0 #res It is the result of the number of each group
res+=720 #(1) First turn clockwise for two turns .
res+=func(first,n) #(2) Turn counterclockwise to the position of the first number . Anticlockwise, use the end to subtract the beginning
res+=360 #(3) Turn counterclockwise .
res+=func(first,middle) #(4) Rotate clockwise to the second number . Clockwise, use the beginning minus the end
res+=func(last,middle) #(5) The pointer turns counterclockwise to the third number . Anticlockwise, use the end to subtract the beginning
d.append(res) # Store the results of the calculation of each group in the list , So that they can be output together
n,first,middle,last=map(int,input().split()) # Continue to enter in order to enter the next cycle
for i in range(len(d)): # Output results
print(d[i])When I first saw this problem, I thought it was very difficult , Because it looks complicated . But I still tried it , It's not difficult to find , Is the most basic mathematical knowledge , There is no hard Algorithm . therefore , When you come across a seemingly difficult problem , And don't give up , Try to do it , To analyze , Maybe it's not very difficult , Or maybe it's really a little difficult , But how do you know if you will not try , What if you make it yourself ? So don't set limits on yourself , Try boldly , To challenge .
The above program gives more detailed comments , For novice Xiaobai's reference . The idea of program design or code implementation is not optimal , You are welcome to correct your mistakes or give better ideas .
I am a rookie who wants to be Kunpeng , Everyone's encouragement is my driving force , Welcome to like collection comments !
边栏推荐
- 【Numpy和Pytorch的数据处理】
- Attach the simplified sample database to the SQLSERVER database instance
- Package bedding of components
- 撲克牌遊戲程序——人機對抗
- 7-3 构造散列表(PTA程序设计)
- Experiment five categories and objects
- 7-15 h0161. Find the greatest common divisor and the least common multiple (PTA program design)
- JS several ways to judge whether an object is an array
- 为什么要使用Redis
- Redis实现分布式锁原理详解
猜你喜欢

The difference between cookies and sessions
![[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP](/img/d6/109042b77de2f3cfbf866b24e89a45.png)
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP

强化学习基础记录

强化学习基础记录

. Net6: develop modern 3D industrial software based on WPF (2)

【手撕代码】单例模式及生产者/消费者模式

7-5 走楼梯升级版(PTA程序设计)

(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。

MATLAB打开.m文件乱码解决办法

FAQs and answers to the imitation Niuke technology blog project (I)
随机推荐
自定义RPC项目——常见问题及详解(注册中心)
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
重载和重写的区别
Experiment 8 exception handling
.Xmind文件如何上传金山文档共享在线编辑?
Reinforcement learning series (I): basic principles and concepts
Redis实现分布式锁原理详解
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
C language Getting Started Guide
附加简化版示例数据库到SqlServer数据库实例中
Detailed explanation of redis' distributed lock principle
Strengthen basic learning records
Canvas foundation 1 - draw a straight line (easy to understand)
3. Input and output functions (printf, scanf, getchar and putchar)
Read only error handling
Leetcode. 3. Longest substring without repeated characters - more than 100% solution
Renforcer les dossiers de base de l'apprentissage
String ABC = new string ("ABC"), how many objects are created
Leetcode.3 无重复字符的最长子串——超过100%的解法
Custom RPC project - frequently asked questions and explanations (Registration Center)