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

Basic practice of Blue Bridge Cup alphabet graphics python|csdn creation punch in

編輯:Python

Blue Bridge Cup Based on practice Alphabetic figure python

  • Resource constraints
  • Problem description
  • Input format
  • Output format
  • The sample input
  • The sample input
  • Data scale and agreement
  • Implementation code
  • matters needing attention
    • 1. Create a two-dimensional empty list
    • 2.26 Traversal of letters (ord Functions and chr Use of functions )
    • Examine the subject

Resource constraints

The time limit :1.0s Memory limit :256.0MB

Problem description

The use of letters can form some beautiful graphics , Here is an example :

ABCDEFG

BABCDEF

CBABCDE

DCBABCD

EDCBABC

This is a 5 That's ok 7 The graph of the column , Please find out the law of this figure , And output a n That's ok m The graph of the column .

Input format

The input line , Contains two integers n and m, The number of columns representing the number of rows of the graph you want to output .

Output format

Output n That's ok , Every m Characters , For your graphics .

The sample input

5 7

The sample input

ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC

Data scale and agreement

1 <= n, m <= 26.

Implementation code

a,b=map(int,input().split()) #map() Map the specified sequence according to the provided function ,input().split() Enter multiple values at the same time. The data type is str
list1=[[0 for n in range(26)] for m in range(26)]
list2=[[0 for n in range(b)] for m in range(a)]
for n in range(26):
for m in range(26):
if m<n:
list1[n][m]=ord('A')+n-m
else:
list1[n][m]=ord('A')+m-n
for i in range(a):
for x in range(b):
list2[i][x]=list1[i][x]
print(chr(list2[i][x]),end=' ')
print()

matters needing attention

1. Create a two-dimensional empty list

list2=[[0 for n in range(b)] for m in range(a)]

Where the front bracket represents the column , The following parentheses represent the line
That is to create a Line contains b A list of elements

2.26 Traversal of letters (ord Functions and chr Use of functions )

26 Let's use... First ord The function converts it to its corresponding ASCII value
Use after addition and subtraction chr Function restore

a=ord('A')
print(a)
b=chr(a)
print(b)

ord() Function return type is int type
You can add and subtract
chr() Function and ord() The function works the opposite

Examine the subject

There is no space between the letters in the output data in the title , It's easy to make mistakes


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