#学习笔记
#用以练习python基础
#
Original title Link: https://www.patest.cn/contests/pat-b-practise/1050
1050. Spiral Matrix (25)
The subject requires that the given n positive integers be filled in the "Spiral Matrix" in a non-ascending order. The so-called "spiral Matrix" refers to the 1th grid in the upper left corner, which is filled in a clockwise spiral direction. The scale of the requirement matrix is m row n column, satisfies the condition: M*n equals n;m>=n; and M-n takes the minimum value from all possible values.
Input format:
The input gives a positive integer n in line 1th, and the 2nd line gives n a positive integer to be filled. All numbers do not exceed4, and adjacent numbers are separated by spaces.
Output format:
Output Spiral matrix. N numbers per line, total m rows. Adjacent numbers are separated by 1 spaces, and there must be no extra spaces at the end of a line.
Input Sample:
1237 76 20 98 76 42 53 95 60 81 58 93
Sample output:
98 95 9342 37 8153 20 7658 60 76
AC Code
Import mathn=int (Input ()) X=10001for i in range (1,n+1): n1=min (I,int (n/i)) m1=max (I,int (n/i)) if m1-n1<=x and n % n1 ==0 and n % m1 ==0: x= m1-n1 n=n1 m=m1l =list (str (input ()). Split (' ')) k=[]for i in l: if i.isalnum () = = True: k.append (int (i)) K.sort (reverse=true) dx=[0,1,0,-1]dy=[1,0, -1,0]# right bottom left Upper Map=[[0 for i in range (n)] for i in range (m)]t=d=x=y=0while true: map[x][y]=k[t] t=t+1 if t==n: break if x+dx[d] >=m: d = (d + 1) % 4 if y+dy[d] >=n: d = (d + 1) % 4 if map[x+dx[d]][y+dy[d]] !=0: d = (d + 1) % 4 x=x+dx[d] y=y+dy[d]for i in map: p=0 for j in i: if p!=0 : print (' ', end= ') print (j,end= ") p = 1 print ()
Original title Link: https://www.patest.cn/contests/pat-b-practise/1048
1048. Digital encryption (20)
A digital encryption method is required for this subject. First fixed an encryption with a positive integer A, any positive integer b, each of its 1 digits and a corresponding position on the number of the following operation: to the odd digits, the corresponding bit of the number added to 13 to take the remainder--here with J for 10, Q for 11, K for 12, and dual digits minus a number of a number, If the result is negative, then add 10. This makes the digit 1th.
Input format:
The input is given a and b in a row, each of which is a positive integer of no more than 100 bits, separated by a space.
Output format:
Outputs the encrypted result in a row.
Input Sample:
1234567 368782971
Sample output:
3695q8118
AC Code
Import copyl=list (str (input ())). Split (' ')) A=list (l[0]) b=list (l[1]) a.reverse () b.reverse () y=[' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' J ', ' Q ', ' K ']c=[]if len (a) > len (b): for i in range (Len (a)-len (b)): b.append (' 0 ') else: for i in Range (len (B)-len (A)): a.append (' 0 ') for i in Range (len (A)): if (i+1) %2 == 0: x=int (B[i])-int (A[i]) if x <0: c.append (x+10) else: c.append ( x) else: x= (int (b[i]) +int (A[i]))%13 c.append (Y[x]) c.reverse () For i in c: print (i,end= ")
1017. A divided by B (20)
The subject requires a A/b, where A is a positive integer that does not exceed 1000 bits, and B is a 1-bit positive integer. You need to output the quotient Q and the remainder r so that a = B * Q + R is set up.
Input format:
The input is given a and B in 1 rows, and the middle is separated by 1 spaces.
Output format:
In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.
Input Sample:
123456789050987654321 7
Sample output:
17636684150141093474 3
AC Code
L=list (str (input)). Split (")) A=int (l[0]) b=int (l[1]) print (a//b,a%b)
This topic can be seen in Python's convenience, such as in C + + not so directly
This article is from the "Chauncey" blog, make sure to keep this source http://cqwujiang.blog.51cto.com/10808946/1919696
Python Basics Exercises Pat Water problem (iv)