当前位置:网站首页>[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
2022-06-30 03:35:00 【M4chael1】
subject 1: Based on practice Decimal to hexadecimal

Their thinking
Method 1 : recursive , Short division
Method 2 :format
Decimal to hexadecimal :format(n, ‘X’)
Decimal to octal :format(n, ‘o’)
Hexadecimal to decimal :int(n, 16)
Octal to decimal :int(n, 8)
Code
# Method 1 recursive
li = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
def hexadecimal(a):
if a > 0:
hexadecimal(a // 16)
print(li[a % 16], end='')
a = int(input())
if a == 0:
print(li[a], end='')
else:
hexadecimal(a)
# Method 2 format
a = int(input())
print(format(a, 'X'))
subject 2: Based on practice Hexadecimal to decimal

Their thinking
Method 1 : loop
Method 2 :int()
Code
# Method 1 : loop
n = input()
li = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
sum = 0
i = 0
for item in n[::-1]:
sum = sum + (li.index(item) * pow(16, i))
i+=1
print(sum)
# Method 2 :int()
n = input()
print(int(n, 16))
subject 3: Based on practice Hexadecimal to octal

Their thinking
Method 1 : First convert decimal , Retransfer octal ( Overtime , Ideas : Convert hex to binary , A hexadecimal number is a 4 Binary of bit , No code )
Method 2 :int() format()
Code
# Method 1 : First convert decimal , Retransfer octal ( Overtime , Ideas : Convert hex to binary , A hexadecimal number is a 4 Binary of bit )
li = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
n = int(input())
ans = []
for i in range(n):
# Hexadecimal to decimal
num = input()
sum = 0
j = 0
for item in num[::-1]:
sum = sum + (li.index(item) * pow(16, j))
j+=1
# Decimal to octal
ansItem = []
if sum == 0:
ans.append(0)
while sum > 0:
ansItem.append(str(sum % 8))
sum = sum // 8
ans.append(int(''.join(ansItem[::-1])))
for i in range(n):
print(ans[i])
# Method 2 :int() format()
n = int(input())
ans = []
for i in range(n):
num = input()
ans.append(format(int(num, 16), 'o'))
for i in range(n):
print(ans[i])
subject 4: Based on practice Sequence sorting

Their thinking
sort、sorted Sort
sort And sorted difference :
sort Is used in the list The method on the ,sorted You can sort all iterable objects .
list Of sort Method returns an operation on an existing list , No return value , And built-in functions sorted Method returns a new one list, Instead of operating on the basis of the original .(https://www.runoob.com/python/python-func-sorted.html)
Code
n = int(input())
intList = list(map(int, input().split()))
intList.sort()
for i in range(n):
print(intList[i], end=' ')
边栏推荐
- How to use Jersey to get the complete rest request body- How to get full REST request body using Jersey?
- MySQL performance optimization (5): principle and implementation of master-slave synchronization
- Golang BiliBili live broadcast bullet screen
- JS conversion of letters and numbers
- Dripping backward (II)
- 【十分钟】manim安装 2022
- Number of students from junior college to Senior College (III)
- Some common functions and precautions
- F1c100s self made development board debugging process
- Auto. JS learning notes 16: save to the mobile phone by project, instead of saving a single JS file every time, which is convenient for debugging and packaging
猜你喜欢
![[wechat applet] how did the conditional rendering list render work?](/img/db/4e79279272b75759cdc8d6f31950f1.png)
[wechat applet] how did the conditional rendering list render work?

Use common fileUpload to upload files

General paging (2)

专升本语文资源整理

1152_ Makefile learning_ Pattern matching rules

51 single chip microcomputer indoor environment monitoring system, mq-2 smoke sensor and DHT11 temperature and humidity sensor, schematic diagram, C programming and simulation

Redis high concurrency distributed locks (learning summary)

Hisense A7 ink screen mobile phone cannot be started

TiDB 6.0:让 TSO 更高效丨TiDB Book Rush

Arrangement of language resources of upgraded version
随机推荐
将DataBinding整合到Activity/Fragment的一种极简方式
C [advanced part] C generic [need to be further supplemented: generic interfaces and instances of generic events]
F1c100s self made development board debugging process
实用调试技巧
Realization of BFS in C language by storing adjacency matrix of graph
Learning cyclic redundancy CRC check
Simple custom MVC optimization
Number of students from junior college to Senior College (III)
The next change direction of database - cloud native database
C [advanced] C interface
C#【高级篇】 C# 接口(Interface)
The 5-year Android development interview took 20 days to join Alibaba
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
[ten minutes] manim installation 2022
Openssl3.0 learning 22 provider decoder
Use of foreach in QT
Is the largest layoff and salary cut on the internet coming?
ZABBIX trigger explanation
Sorting method of administrative route code letter + number
Half a year after joining the company, I was promoted to a management post