Love丶FFC's Blog
成成最近在搭建一个网站,其中一些页面的部分内容来自数据库中不同的数据记录,但是页面的基本结构是相同的。例如,对于展示用户信息的页面,当用户为 Tom 时,网页的源代码是
而当用户为 Jerry 时,网页的源代码是
这样的例子在包含动态内容的网站中还有很多。为了简化生成网页的工作,成成觉得他需要引入一套模板生成系统。
模板是包含特殊标记的文本。成成用到的模板只包含一种特殊标记,格式为 {{ VAR }},其中 VAR 是一个变量。该标记在模板生成时会被变量 VAR 的值所替代。例如,如果变量 name = "Tom",则 {{ name }} 会生成 Tom。具体的规则如下:
·变量名由大小写字母、数字和下划线 (_) 构成,且第一个字符不是数字,长度不超过 16 个字符。
·变量名是大小写敏感的,Name 和 name 是两个不同的变量。
·变量的值是字符串。
·如果标记中的变量没有定义,则生成空串,相当于把标记从模板中删除。
·模板不递归生成。也就是说,如果变量的值中包含形如 {{ VAR }} 的内容,不再做进一步的替换。
输入的第一行包含两个整数 m, n,分别表示模板的行数和模板生成时给出的变量个数。
接下来 m 行,每行是一个字符串,表示模板。
接下来 n 行,每行表示一个变量和它的值,中间用一个空格分隔。值是字符串,用双引号 (") 括起来,内容可包含除双引号以外的任意可打印 ASCII 字符(ASCII 码范围 32, 33, 35-126)。
输出包含若干行,表示模板生成的结果。
11 2
<!DOCTYPE html>
<html>
<head>
<title>User {{ name }}</title>
</head>
<body>
<h1>{{ name }}</h1>
<p>Email: <a href="mailto:{{ email }}">{{ email }}</a></p>
<p>Address: {{ address }}</p>
</body>
</html>
name "David Beckham"
email "david@beckham.com"
<!DOCTYPE html>
<html>
<head>
<title>User David Beckham</title>
</head>
<body>
<h1>David Beckham</h1>
<p>Email: <a href="mailto:david@beckham.com">david@beckham.com</a></p>
<p>Address: </p>
</body>
</html>
0 ≤ m ≤ 100
0 ≤ n ≤ 100
输入的模板每行长度不超过 80 个字符(不包含换行符)。
输入保证模板中所有以 {{ 开始的子串都是合法的标记,开始是两个左大括号和一个空格,然后是变量名,结尾是一个空格和两个右大括号。
输入中所有变量的值字符串长度不超过 100 个字符(不包括双引号)。
保证输入的所有变量的名字各不相同。
1.使用二维列表保存变量名和变量值
2.遍历模板,替换存在的变量
3.遍历模板,替换不存在的变量,如果发现递归变量,将递归变量暂时转换
4.将递归变量恢复原状
TemplateRow, NOV = map(int, input().split()) # 输入模板行数,变量个数 Template = ['0' for i in range(TemplateRow)] # 模板列表 Variable = [['0', '0'] for i in range(NOV)] # 变量列表,[0]为变量名,[1]为变量值 for i in range(TemplateRow): # 输入模板 Template[i] = input() for i in range(NOV): # 输入变量 Variable[i] = input().split() if Variable[i].__len__() > 2: for j in range(2, Variable[i].__len__()): # 将变量值拼接 Variable[i][1] += ' ' + Variable[i][j] Variable[i][1] = Variable[i][1].replace('"', '') Variable[i] = Variable[i][:2] # 只保留变量名和变量值 for i in range(NOV): # 对存在的变量进行替换 for j in range(TemplateRow): if '{{ ' + Variable[i][0] + ' }}' in Template[j]: # 发现这一行有符合的变量 Template[j] = Template[j].replace('{{ ' + Variable[i][0] + ' }}', Variable[i][1]) for i in range(TemplateRow): # 消除不存在的变量以及保留递归变量 while '{{' and '}}' in Template[i]: Deletevariable = Template[i][Template[i].find('{'):Template[i].find('}') + 2] # 获得{{ var }} for j in range(NOV): if Deletevariable[Deletevariable.rfind('{') + 2:Deletevariable.find('}') - 1] == Variable[j][0]: # 保留递归变量 Swapvariable = Deletevariable Swapvariable = Swapvariable.replace('{{', '[[').replace('}}', ']]') Template[i] = Template[i].replace(Deletevariable, Swapvariable) # 将{{ var }}暂时转为[[ var ]] Template[i] = Template[i].replace(Deletevariable, '') # 消除不存在的变量 Template[i] = Template[i].replace('[', '{').replace(']', '}') # 将递归变量恢复原状 print(Template[i])
Gealpaste
2003, 361 9354 296 300 cialis 20 mg
cheap jordans
Read reviews and was a little hesitant since I had already inputted my order. quite possibly but thank god, I had no issues. simillar to the received item in a timely matter, they are in new condition. either way so happy I made the purchase. Will be definitely be purchasing again.
cheap jordans https://www.cheaprealjordan.com/
cheap louis vuitton bags
Read reviews and was a little hesitant since I had already inputted my order. or just but thank god, I had no issues. including the received item in a timely matter, they are in new condition. manner in which so happy I made the purchase. Will be definitely be purchasing again.
cheap louis vuitton bags https://www.louisvuittonsoutletonline.com/
cheap jordan shoes
Read reviews and was a little hesitant since I had already inputted my order. aka but thank god, I had no issues. for instance the received item in a timely matter, they are in new condition. manner in which so happy I made the purchase. Will be definitely be purchasing again.
cheap jordan shoes https://www.realjordansshoes.com/
Gealpaste
can i buy priligy over the counter The median survival time was similar among the three groups p 0
intuido
buy cialis 5mg daily use 2016; Matos et al
intuido
1 for more information on survivorship care plans cialis 10mg PVN CRH in the presence of RU 486
AshLit
prinivil 20 mg tablet
Richardatone
augmentin uk
Davidevelf
atenolol 50 mg tablet price in india
JackLit
lisinopril 104
AshLit
where can i buy atarax in uk
Davidevelf
medrol 32
akun gacor vip
Excellent site. A lot of useful info here.
I am sending it to some buddies ans additionally sharing in delicious.
And of course, thank you to your effort!
crypto signals
I every time emailed this blog post page to all my friends,
for the reason that if like to read it afterward my contacts will too.
my webpage – crypto signals
AshLit
buy sildalis 120 mg
Nfjbjm
buy fenofibrate 200mg generic fenofibrate cheap tricor 200mg cheap
Elwoodexcix
erythromycin topical
Michaelsmopy
cialis 40 mg tablets
Davidevelf
amoxicillin pill
JackLit
albenza 200 mg tablet
SFRVcPKeU
This innovation of delivering drugs through the breast skin will apply to women who don t need a systemic effect online cialis pharmacy
Autmdo
tricor 160mg us order fenofibrate fenofibrate 160mg without prescription
SamLit
buy diflucan pill
SamuelEcors
dexamethasone 6 tablet
Richardatone
buy atarax online uk
AlanLit
atarax 10mg price in india
Michaelsmopy
all in one pharmacy
ZakLit
atenolol chlorthalidone
EyeLit
antibiotics levaquin
ZakLit
zithromax pills
SueLit
lipitor generic canada
Davidevelf
dexamethasone 4mg
Michaelsmopy
canadian pharmacy no rx needed
IvyLit
glucophage brand name price
SamLit
brand name lipitor cost
AshLit
cheap canadian pharmacy
JosephKip
dexamethasone 50 mg
Elwoodexcix
legitimate canadian pharmacies
ZakLit
robaxin 500mg cost
Williamjotly
atarax 50 mg tablet
AshLit
amoxicillin in usa
Williamjotly
tadalafil 2.5 mg tablets india
AlanLit
atenolol over the counter
JosephKip
discount cymbalta 60 mg
AlanLit
atarax cost canada
Williamjotly
phenergan price uk
SamuelEcors
azithromycin 500 mg tablets
AlanLit
baclofen 10 mg cost australia
AlanLit
generic robaxin 750
Michaelsmopy
levofloxacin
SamuelEcors
robaxin 500 mg tablet
DarrylBox
lipitor 10mg generic
Williamjotly
medicine prednisolone 5mg
IvyLit
phenergan 6.25
SamuelEcors
dexamethasone 4mg
JoeLit
lipitor medication
DarrylBox
prazosin 8 mg
Elwoodexcix
baclofen generic brand
AshLit
where to buy terramycin
Davidevelf
cialis for sale in canada
DarrylBox
levaquin 750 mg
SamLit
dexona drug
SueLit
tamoxifen for sale uk
Davidevelf
rate online pharmacies
Richardatone
lipitor online
DarrylBox
pharmacy delivery
EyeLit
buy metformin online without a prescription
Richardatone
order glucophage
ZakLit
baclofen prescription cost
SamuelEcors
triamterene hctz 37.5 25
Elwoodexcix
30 prazosin 1mg cap
SamuelEcors
atarax generic otc
SamLit
retin a micro
ZakLit
levaquin.com
Davidevelf
cymbalta 20 mg price
Richardatone
lipitor generic over the counter
AlanLit
metformin canada over the counter
AlanLit
baclofen 20 mg price in india
JosephKip
atarax sale
SamLit
prednisolone 5mg without prescription
JosephKip
atarax 25mg tab
DavisIgnip
cymbalta online no prescription
Michaelsmopy
retin a 01
CurtisHed
tamoxifen 10 mg tablet price
AlanLit
baclofen 25mg
Michaelsmopy
atarax tablets
Michaelsmopy
atenolol 25 mg
DarrylBox
prednisolone for sale uk
IvyLit
tretinoin paypal
SamLit
robaxin/methocarbamol 500mg
DarrylBox
levaquin antibiotics
Richardatone
purchase prednisolone 5mg tablets
SamuelEcors
prednisolone brand name india
EyeLit
cialis generic from india
DavisIgnip
atarax online
Davidevelf
prazosin 1 mg coupon
Williamjotly
prazosin 4mg
SamuelEcors
robaxin price south africa
Williamjotly
phenergan otc uk
Elwoodexcix
baclofen cost
DavisIgnip
pharmacy store
IvyLit
phenergan 25mg nz
SueLit
strattera 60 mg capsules
JoeLit
apo prednisone
MaryLit
canada synthroid cost
JosephKip
voltaren gel cost
Richardatone
buy lisinopril 2.5 mg online
AlanLit
doxycycline otc uk
Pkquwk
cheap cialis pill buy generic sildenafil 50mg sildenafil oral
AshLit
diflucan 100
SamuelEcors
keflex 219
Elwoodexcix
synthroid 60 mg
DavisIgnip
diclofenac gel for sale
SamLit
amoxicillin 3109
Richardatone
buy generic strattera
DavisIgnip
synthroid 200 mcg tablet
SamuelEcors
online plavix
IvyLit
buy strattera online europe
Michaelsmopy
suhagra 100 online purchase
Xkfugh
purchase zaditor buy zaditor paypal buy imipramine generic
Williamjotly
can you buy amoxicillin uk
SueLit
lisinopril price
MaryLit
order prednisone 10mg
AshLit
augmentin over the counter
Richardatone
plavix canada price
ZakLit
bactrim buying
Elwoodexcix
2500 mg amoxicillin
Richardatone
keflex capsules 250mg
JosephKip
azithromycin order
SueLit
doxycycline pills buy
JosephKip
can you buy generic celebrex
AshLit
50 mg phenergan
Davidevelf
where to buy prednisone in australia
Davidevelf
buy flomax online
IvyLit
phenergan 25mg tablets uk
Michaelsmopy
buy suhagra 50 online
SamLit
where can you buy flomax
Michaelsmopy
canadian pharmacy 24 com
Michaelsmopy
buy synthroid 200 mcg
AshLit
retino 0.25
AshLit
compare diclofenac cream
SamuelEcors
generic for zestril
Richardatone
phenergan otc canada
Hszrwb
buy minoxytop without a prescription ed pills that really work the best ed pill
DarrylBox
zestril 5 mg india
AlanLit
retino
SamuelEcors
where to buy clopidogrel
DarrylBox
doxycycline 40 mg
JosephKip
lisinopril for sale uk
Zcpeta
where can i buy precose buy prandin 1mg generic fulvicin 250mg generic
IvyLit
generic lyrica 2017
IvyLit
celebrex 200mg capsules