每个程序都回涉及到文本处理,如拆分字符串、搜索、替换、词法分析等。许多任务都可以通过内建的字符串方法来轻松解决,但更复杂的操作就需要正则表达式来解决。

1、针对任意多的分隔符拆分字符串

In [1]: line = 'asdf fjdk; afed, fjek,asdf,    foo'
#使用正则模块
In [2]: import re
#使用正则split方法可以匹配多分割符
In [3]: re.split(r'[;,\s]\s*',line)
Out[3]: ['asdf', 'fjdk', 'afed', 'fjek', 'asdf', 'foo']
#使用捕获组分割会将匹配的文本也包含在最终结果中
In [4]: re.split(r'(;|,|\s)\s*',line)
Out[4]: ['asdf', ' ', 'fjdk', ';', 'afed', ',', 'fjek', ',', 'asdf', ',', 'foo']
#如果不想在结果中看到分隔符,可以受用?:的形式使用非捕获组
In [5]: re.split(r'(?:,|;|\s)\s*',line)
Out[5]: ['asdf', 'fjdk', 'afed', 'fjek', 'asdf', 'foo']

2、在字符串的开头或结尾处做文本匹配

In [6]: url = 'https://www.baidu.com'
#检查字符串的结尾,匹配则返回True
In [7]: url.endswith('.com')
Out[7]: True
In [8]: url.endswith('.cn')
Out[8]: False
#检查字符串的开头,匹配则返回true
In [10]: url.startswith('https:')
Out[10]: True
In [11]: url.startswith('http:')
Out[11]: False In [1]: import os
In [2]: filenames = os.listdir('.')
In [3]: filenames
Out[3]:
['.tcshrc',
'.bash_logout',
'.mysql_history',
'Python-3.7.0.tgz',
'.bash_history',
'.cache',
'anaconda-ks.cfg',
'.ipython',
'.cshrc',
'.bashrc',
'.viminfo',
'Python-3.7.0',
'mysql-boost-8.0.12.tar.gz',
'heapq_queue.py',
'mysql-8.0.12',
'.bash_profile']
#应用匹配开头字符串过滤
In [4]: [i for i in filenames if i.startswith('.')]
Out[4]:
['.tcshrc',
'.bash_logout',
'.mysql_history',
'.bash_history',
'.cache',
'.ipython',
'.cshrc',
'.bashrc',
'.viminfo',
'.bash_profile']
#多个结果匹配时使用元组集合
In [5]: [i for i in filenames if i.endswith(('.py','.gz','.tgz'))]
Out[5]: ['Python-3.7.0.tgz', 'mysql-boost-8.0.12.tar.gz', 'heapq_queue.py']
#判断目录中是否有.py结尾的文件
In [6]: any(i.endswith('.py') for i in filenames)
Out[6]: True
#应用列子解析网页或文本内容
from urllib.request import urlopen def read_date(name):
if name.startswith(('http:','https:','ftp:')):
return urlopen(name).read().decode()
else:
with open(name) as f:
return f.read() result = read_date('test.txt')
print(result) #也可以使用正则匹配
In [9]: import re In [10]: re.match('http:|https:|ftp:','https://www.baidu.com')
Out[10]: <re.Match object; span=(0, 6), match='https:'>

3、利用shell通配符做字符串匹配

#利用fnmatch模块中的fnmatch和fnmatchcase函数匹配文本
In [12]: from fnmatch import fnmatch,fnmatchcase In [13]: fnmatch('foo.txt','*.txt')
Out[13]: True In [14]: fnmatch('foo.txt','?oo.txt')
Out[14]: True In [15]: names = ['dat01.csv','dat99.csv','config.ini','foo.py'] In [18]: [i for i in names if fnmatch(i,'dat[0-9]*.csv')]
Out[18]: ['dat01.csv', 'dat99.csv']
#对于Windows操作系统时使用fnmatch函数时,匹配它不区分大小写,这时我们可以使用fnmatchcase函数来代替,它完全按照提供的字符串来匹配
In [2]: fnmatch('foo.txt','*.TXT')
Out[2]: True In [3]: fnmatchcase('foo.txt','*.TXT')
Out[3]: False #推倒式过滤文件名的字符串
In [20]: addresses = [
...: '5412 N CLARK ST',
...: '1060 W ADDISON ST',
...: '1039 W GRANVILLE AVE',
...: '2122 N CLARK ST',
...: '4802 N BROADWAY',
...: ] In [21]: [i for i in addresses if fnmatch(i,'*ST')]
Out[21]: ['5412 N CLARK ST', '1060 W ADDISON ST', '2122 N CLARK ST'] In [22]: [i for i in addresses if fnmatch(i,'*CLARK*')]
Out[22]: ['5412 N CLARK ST', '2122 N CLARK ST']

4、文本模式的匹配和查找

对于简单的文字匹配我们只需要使用基本的字符串方法str.find()、str.endswith()、str.startswith(),对于更复杂的匹配就需要使用正则表达式模块re来匹配了

In [23]: text1 = 'today is 10/19/2018.Pycon starts 3/13/2019.'

In [24]: import re

In [25]: re.match(r'\d+/\d+/\d+',text1)

In [28]: re.findall(r'\d+/\d+/\d+',text1)
Out[28]: ['10/19/2018', '3/13/2019'] In [29]: text2 = '11/20/2018' In [30]: re.match(r'\d+/\d+/\d+',text2)
Out[30]: <re.Match object; span=(0, 10), match='11/20/2018'> In [31]: result = re.match(r'(\d+)/(\d+)/(\d+)',text2) In [32]: result.groups()
Out[32]: ('', '', '') In [33]: result.group(0)
Out[33]: '11/20/2018' In [34]: result.group(1)
Out[34]: '' In [35]: result.group(2)
Out[35]: '' In [36]: result.group(3)
Out[36]: ''
#分组取出所有的日期并按格式输出
In [39]: text1 = 'today is 10/19/2018.Pycon starts 3/13/2019.' In [40]: for month,day,year in re.findall(r'(\d+)/(\d+)/(\d+)',text1):
...: print('{}-{}-{}'.format(year,month,day))
...:
2018-10-19
2019-3-13 #如果文本数据比较大可以使用finditer()方法,以迭代器的方法匹配
In [43]: text1 = 'today is 10/19/2018.Pycon starts 3/13/2019.' In [44]: for i in re.finditer(r'(\d+)/(\d+)/(\d+)',text1):
...: print(i.groups())
...:
('', '', '')
('', '', '')

5、查找和替换文本

对于简单的文本模式,可以使用str.replace()方法即可

In [45]: text = 'abcabcabcabc'

In [46]: text.replace('a','ee')
Out[46]: 'eebceebceebceebc'

针对更为复杂的匹配,可以使用re模块中的sub()方法

In [47]: text3 = 'today is 10/19/2018. pycon starts 3/13/2013.'

In [49]: re.sub(r'(\d+)/(\d+)/(\d+)',r'\3-\1-\2',text3)
Out[49]: 'today is 2018-10-19. pycon starts 2013-3-13.'

更为复杂的例子,如把日期换成字符格式

In [54]: text3 = 'today is 10/19/2018. pycon starts 3/13/2013.'

In [55]: from calendar import month_abbr

In [56]: def change_date(m):
...: mon_name = month_abbr[int(m.group(1))]
...: return '{} {} {}'.format(m.group(2),mon_name,m.group(3))
...:
...: In [57]: re.sub(r'(\d+)/(\d+)/(\d+)',change_date,text3)
Out[57]: 'today is 19 Oct 2018. pycon starts 13 Mar 2013.'
#subn()可以返回完成了多少次替换
In [58]: re.subn(r'(\d+)/(\d+)/(\d+)',change_date,text3)
Out[58]: ('today is 19 Oct 2018. pycon starts 13 Mar 2013.', 2)

6、以不区分大小写的方式对文本做查找和替换

要进行不分区大小写的文本操作时,可以使用re模块进程操作时都要加上re.IGNORECASE标记

In [60]: text = 'UPPER PYTHON,lower python, mixed Python'
In [61]: re.findall('python',text,flags=re.IGNORECASE)
Out[61]: ['PYTHON', 'python', 'Python']
import re
def matchcase(word):
def replace(m):
text = m.group()
if text.isupper():
return word.upper()
elif text.islower():
return word.lower()
elif text[0].isupper():
return word.capitalize()
else:
return word
return replace
#保持原字符大小写或首字母大写替换实例
text = 'UPPER PYTHON,lower python,Mixed Python'
print(re.sub('python',matchcase('snake'),text,flags=re.IGNORECASE))

7、最短匹配的正则表达式

str_pat = re.compile(r'\"(.*)\"')
text1 = 'computer says "no."'
str_pat.findall(text1)
Out[18]: ['no.']
text2 = 'computer says "no." phone says "yes."'
str_pat.findall(text2) #在使用.*贪婪匹配时它将匹配尽可能多的匹配项
Out[20]: ['no." phone says "yes.']
str_pat = re.compile(r'\"(.*?)\"') #只需要在多匹配后加上?号,就会以最少的匹配模式进行匹配
str_pat.findall(text2)
Out[22]: ['no.', 'yes.']

8、多行模式的正则表达式

comment = re.compile(r'python(.*?)end')
text1 = 'python is ver good \n so so end'
comment.findall(text1) #.*匹配不到换行符
Out[27]: []
comment = re.compile(r'python(.*?)end',flags=re.DOTALL) #加上标记re.DOTALL将匹配所有的字符包括换行符
comment.findall(text1)
Out[29]: [' is ver good \n so so ']
comment = re.compile(r'python((?:.|\n)*?)end') #(?:.|\n)会指定一个非捕获组,它只做匹配但不捕获结果,也不分配组号
comment.findall(text1)
Out[31]: [' is ver good \n so so ']

9、将Unicode文本统一表示为规范形式是

s1 = 'spicy\u00f1o'  #它使用的是(U+00F1)全组成的(fully composed)
s2 = 'spicy\u0303o' #它使用的是(U+0303)拉丁字母组合而成
s1 == s2 #所以字符比较是不相等的
Out[35]: False
s1
Out[36]: 'spicyño'
s2
Out[37]: 'spicỹo'

10、从字符串中去掉不需要的字符

#strip()方法用来从字符串的开始和结尾处去掉字符,lstrip()和rstrip()分别从左或右开始执行去除字符操作,默认去除的是空格符,也可以指定
In [21]: s = ' hello world \n' In [22]: s.strip()
Out[22]: 'hello world' In [23]: s.lstrip()
Out[23]: 'hello world \n' In [24]: s.rstrip()
Out[24]: ' hello world' In [25]: t = '-----hello=====' In [26]: t.lstrip('-') #指定去除字符
Out[26]: 'hello=====' In [27]: t.strip('-=') #可以指定多个字符
Out[27]: 'hello' #使用上面的方法不能去除中间的字符,要去除中间的字符可以使用replace()方法或正则表达式替换
In [28]: s.replace(' ','')
Out[28]: 'helloworld\n' In [29]: re.sub('\s+', '',s)
Out[29]: 'helloworld'

11、对齐文本字符串

#对应基本的字符串对齐,可以使用字符串方法ljust()、rjust()和center(),分别表示左对齐,右对齐和居中对齐,它还可以填充字符可选参数
In [31]: text = 'hello world' In [32]: text.ljust(30)
Out[32]: 'hello world ' In [33]: text.rjust(30)
Out[33]: ' hello world' In [34]: text.center(30)
Out[34]: ' hello world ' In [35]: text.center(30,'=')
Out[35]: '=========hello world==========' #format()函数也可以用来完成对齐任务,需要做的就是合理利用'<'、'>'和'^'字符分别表示左对齐、右对齐和居中对齐,并提供一个期望的宽度值,如果想指定填充字符,可以在对齐符前指定:
In [36]: format(text,'>20')
Out[36]: ' hello world' In [37]: format(text,'<20')
Out[37]: 'hello world ' In [38]: format(text,'^20')
Out[38]: ' hello world ' In [39]: format(text,'=^20')
Out[39]: '====hello world=====' In [40]: format(text,'=^20s')
Out[40]: '====hello world=====' In [41]: format(text,'*^20s')
Out[41]: '****hello world*****'
#当格式化多个值时,也可以使用format()方法
In [42]: '{:>10s}{:<10s}'.format('hello','world')
Out[42]: ' helloworld ' In [43]: '{:#>10s} {:&<10s}'.format('hello','world')
Out[43]: '#####hello world&&&&&'

12、字符串链接及合并

#合并的字符串在一个序列或可迭代对象中,最好的方法是使用join()方法
In [44]: data = ['I','like','is','python'] In [45]: ' '.join(data)
Out[45]: 'I like is python' In [46]: ','.join(data)
Out[46]: 'I,like,is,python' #利用生成器表达式转换后链接字符串会更高效
In [47]: ','.join(str(d) for d in data)
Out[47]: 'I,like,is,python'

13、给字符串中的变量名做插值处理

#在字符串中给变量赋值一般常见的处理方式是使用format()方法
In [5]: str_variable = "{name} today {num} old year" In [6]: str_variable.format(name='zhang',num=20)
Out[6]: 'zhang today 20 old year' #另一种方式是使用format_map()和vars()联合匹配当前环境中的变量名
In [7]: name = 'python' In [8]: num = 18 In [9]: str_variable.format_map(vars())
Out[9]: 'python today 18 old year'
#vars()还可用在类实例上
In [10]: class info:
...: def __init__(self,name,num):
...: self.name = name
...: self.num = num
...: In [11]: a = info('shell',23) In [12]: str_variable.format_map(vars(a))
Out[12]: 'shell today 23 old year'
#对于传递参数不够时将会抛出异常,可以定义一个带有__missing__()方法的字典类来处理
In [13]: class safesub(dict):
...: def __missing__(self,key):
...: return '{' + key + '}'
...: In [14]: del num In [15]: str_variable.format_map(safesub(vars()))
Out[15]: 'python today {num} old year'

14、以固定的列数重新格式化文本

#textwrap模块可以以多种方式重新格式化字符串:
>>> import textwrap
>>> s = "look into eyes, look into my eyes, the eyes,the eyes, \
... the eyes, not around the eyes, don't look around the eyes, \
... look into my eyes, you're under."
>>> print(textwrap.fill(s,70)
... )
look into eyes, look into my eyes, the eyes,the eyes, the eyes, not
around the eyes, don't look around the eyes, look into my eyes, you're
under.
>>> print(textwrap.fill(s,40))
look into eyes, look into my eyes, the
eyes,the eyes, the eyes, not around the
eyes, don't look around the eyes, look
into my eyes, you're under.
>>> print(textwrap.fill(s,40,initial_indent=' '))
look into eyes, look into my eyes, the
eyes,the eyes, the eyes, not around the
eyes, don't look around the eyes, look
into my eyes, you're under.
>>> print(textwrap.fill(s,40,subsequent_indent=' '))
look into eyes, look into my eyes, the
eyes,the eyes, the eyes, not around the
eyes, don't look around the eyes, look
into my eyes, you're under.
#可以通过os.get_terminal_size()来获取终端的尺寸大小
>>> import os
>>> print(textwrap.fill(s,os.get_terminal_size().columns))
look into eyes, look into my eyes, the eyes,the eyes, the eyes, not around the eyes, don't look around
the eyes, look into my eyes, you're under.
>>> print(os.get_terminal_size())
os.terminal_size(columns=105, lines=32)

15、在文本中处理HTML和XML实体

#使用html.escape()函数来替换HTML标签为文本样式
In [1]: s = 'Elements are written aa "<tag>text</tag>".' In [2]: import html In [3]: s
Out[3]: 'Elements are written aa "<tag>text</tag>".' In [4]: html.escape(s)
Out[4]: 'Elements are written aa &quot;&lt;tag&gt;text&lt;/tag&gt;&quot;.'
#忽略quote标签
In [5]: html.escape(s,quote=False)
Out[5]: 'Elements are written aa "&lt;tag&gt;text&lt;/tag&gt;".'
#处理ASCII文本
In [6]: s1 = 'Spicy &quot;Jalapeño&quot.'
In [7]: from html.parser import HTMLParser
In [9]: p = HTMLParser()
In [11]: p.unescape(s1)
Out[11]: 'Spicy "Jalapeño".'
#生成ASCII文本
In [12]: s2 = p.unescape(s1)
In [13]: s2.encode('ascii',errors='xmlcharrefreplace')
Out[13]: b'Spicy "Jalapeño".'
#处理XML实体
In [14]: s3 = 'the prompt is &gt;&gt;&gt;'
In [15]: from xml.sax.saxutils import unescape
In [16]: unescape(s3)
Out[16]: 'the prompt is >>>'

16、文本分词

#从左到右将字符串解析为标记流(stream of tokens)
In [17]: text = 'foo = 23 + 42 * 10' In [18]: tokens= [('NAME','foo'),('EQ','='),('NUM',''),('PLUS','+'),('NUM',''),('TIMES','*'),('NUM','
...: 10')] In [19]: import re
#使用正则表达式
InIn [20]: NAME = r'(?P<NAME>[a-zA_][a-zA-Z_0-9]*)' In [21]: NUM = r'(?P<NUM>\d+)' In [22]: PLUS = r'(?P<PLUS>\+)' In [23]: TIMES = r'(?P<TIMES>\*)' In [24]: EQ = r'(?P<EQ>=)' In [25]: WS = r'(?P<WS>\s+)' In [26]: master_pat = re.compile('|'.join([NAME,NUM,PLUS,TIMES,EQ,WS]))
#使用模式对象的scanner()方法来完成分词操作
In [27]: scanner = master_pat.scanner('foo = 42')
#在给定的文本中重复调用match()方法,一次匹配一个模式,下面是匹配过程
In [28]: scanner.match()
Out[28]: <re.Match object; span=(0, 3), match='foo'> In [29]: _.lastgroup,_.group()
Out[29]: ('NAME', 'foo') In [30]: scanner.match()
Out[30]: <re.Match object; span=(3, 4), match=' '> In [31]: _.lastgroup,_.group()
Out[31]: ('WS', ' ') In [32]: scanner.match()
Out[32]: <re.Match object; span=(4, 5), match='='> In [33]: _.lastgroup,_.group()
Out[33]: ('EQ', '=') In [34]: scanner.match()
Out[34]: <re.Match object; span=(5, 6), match=' '> In [35]: _.lastgroup,_.group()
Out[35]: ('WS', ' ') In [36]: scanner.match()
Out[36]: <re.Match object; span=(6, 8), match=''> In [37]: _.lastgroup,_.group()
Out[37]: ('NUM', '')
#通过生成器函数来转化为代码的形式
In [40]: from collections import namedtuple In [41]: token = namedtuple('token',['type','value']) In [42]: def generate_tokens(pat,text):
...: scanner = pat.scanner(text)
...: for m in iter(scanner.match,None):
...: yield token(m.lastgroup,m.group())
...: In [43]: for tok in generate_tokens(master_pat,'foo = 42'):
...: print(tok)
...:
token(type='NAME', value='foo')
token(type='WS', value=' ')
token(type='EQ', value='=')
token(type='WS', value=' ')
token(type='NUM', value='')
#过滤空格标记
In [45]: tokens = (tok for tok in generate_tokens(master_pat,text) if tok.type != 'WS') In [46]: for tok in tokens:print(tok)
token(type='NAME', value='foo')
token(type='EQ', value='=')
token(type='NUM', value='')
token(type='PLUS', value='+')
token(type='NUM', value='')
token(type='TIMES', value='*')
token(type='NUM', value='')

17、编写一个简单的递归下降解析器

import re
import collections #定义文本分词变量
NUM = r'(?P<NUM>\d+)'
PLUS = r'(?P<PLUS>\+)'
MINUS = r'(?P<MINUS>-)'
TIMES = r'(?P<TIMES>\*)'
DIVIDE = r'(?P<DIVIDE>/)'
LPAREN = r'(?P<LPAREN>\()'
RPAREN = r'(?P<RPAREN>\))'
WS = r'(?P<WS>\s+)' master_pat = re.compile('|'.join([NUM,PLUS,MINUS,TIMES,DIVIDE,LPAREN,RPAREN,WS]))
Token = collections.namedtuple('Token',['type','value']) #过滤文本分词
def generate_tokens(text):
scanner = master_pat.scanner(text)
for m in iter(scanner.match,None):
tok = Token(m.lastgroup,m.group())
if tok.type != 'WS':
yield tok class ExpressionEvaluator:
def parse(self,text):
self.tokens = generate_tokens(text)
self.nexttok = None
self.tok = None
self._advance()
return self.expr() def _advance(self):
self.tok,self.nexttok = self.nexttok,next(self.tokens,None)
def _accept(self,toktype):
if self.nexttok and self.nexttok.type == toktype:
self._advance()
return True
else:
return False
def _expect(self,toktype):
if not self._accept(toktype):
raise SyntaxError('Expected' + toktype) def expr(self):
exprval = self.term()
while self._accept('PLUS') or self._accept('MINUS'):
op = self.tok.type
right = self.term()
if op == 'PLUS':
exprval += right
elif op == 'MINUS':
exprval -= right
return exprval def term(self):
termval = self.factor()
while self._accept('TIMES') or self._accept('DIVIDE'):
op = self.tok.type
right = self.factor()
if op == 'TIMES':
termval *= right
elif op == 'DIVIDE':
termval /= right
return termval def factor(self):
if self._accept('NUM'):
return int(self.tok.value)
elif self._accept('LPAREN'):
exprval = self.expr()
self._expect('RPAREN')
return exprval
else:
raise SyntaxError('Expected NUMBER or LPAREN') if __name__ == '__main__':
e = ExpressionEvaluator()
print(e.parse(''))
print(e.parse('2 + 3'))
print(e.parse('2 + 3 * 4'))
print(e.parse('2 + (3 + 4) * 5'))

18、在字节串上进行文本操作

In [2]: data = b'hello world'

In [3]: data
Out[3]: b'hello world'
#切片
In [4]: data[0:5]
Out[4]: b'hello'
#分隔
In [6]: data.split()
Out[6]: [b'hello', b'world']
#替换
In [7]: data.replace(b'hello',b'python')
Out[7]: b'python world'
#在返回单个切片时将返回ASCII字节表对应的位置
In [8]: data[0]
Out[8]: 104

python3字符串与文本处理的更多相关文章

  1. [转]python3字符串与文本处理

    转自:python3字符串与文本处理 阅读目录 1.针对任意多的分隔符拆分字符串 2.在字符串的开头或结尾处做文本匹配 3.利用shell通配符做字符串匹配 4.文本模式的匹配和查找 5.查找和替换文 ...

  2. python3: 字符串和文本(4)

    16. 以指定列宽格式化字符串[textwrap] https://docs.python.org/3.6/library/textwrap.html#textwrap.TextWrapper 假如你 ...

  3. python3: 字符串和文本(3)

    11. 删除字符串中不需要的字符  strip() 方法能用于删除开始或结尾的字符: lstrip() 和 rstrip() 分别从左和从右执行删除操作 >>> s = ' hell ...

  4. python3: 字符串和文本(2)

    6. 字符串忽略大小写的搜索替换 >>> text = 'UPPER PYTHON, lower python, Mixed Python' >>> re.find ...

  5. python3: 字符串和文本

    1. 分割字符串-使用多个界定符[re.split()] >>> line = 'asdf fjdk; afed, fjek,asdf, foo' >>> impo ...

  6. Python3-Cookbook总结 - 第二章:字符串和文本

    第二章:字符串和文本 几乎所有有用的程序都会涉及到某些文本处理,不管是解析数据还是产生输出. 这一章将重点关注文本的操作处理,比如提取字符串,搜索,替换以及解析等. 大部分的问题都能简单的调用字符串的 ...

  7. Python3 批量替换文本内容

    Python3 批量替换文本内容 示例: # coding:utf8 import os; def reset(): i = 0 path = r"H:\asDemo\workdemo\aw ...

  8. 《Python CookBook2》 第一章 文本 - 过滤字符串中不属于指定集合的字符 && 检查一个字符串是文本还是二进制

    过滤字符串中不属于指定集合的字符 任务: 给定一个需要保留的字符串的集合,构建一个过滤函数,并可将其应用于任何字符串s,函数返回一个s的拷贝,该拷贝只包含指定字符集合中的元素. 解决方案: impor ...

  9. python3字符串

    Python3 字符串 Python字符串运算符 + 字符串连接 a + b 输出结果: HelloPython * 重复输出字符串 a*2 输出结果:HelloHello [] 通过索引获取字符串中 ...

随机推荐

  1. centos Install Docker

    安装必备软件 $ yum -y install iptables iptables-services net-tools vim wget $ wget -P ~ https://github.com ...

  2. 洛谷P3345 [ZJOI2015]幻想乡战略游戏(动态点分治,树的重心,二分查找,Tarjan-LCA,树上差分)

    洛谷题目传送门 动态点分治小白,光是因为思路不清晰就耗费了不知道多少时间去gang这题,所以还是来理理思路吧. 一个树\(T\)里面\(\sum\limits_{v\in T} D_vdist(u,v ...

  3. Java微信公众号安全模式消息解密

    这篇文章主要为大家详细介绍了Java微信公众号安全模式消息解密,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.微信公众平台下载解密工具,导入项目中,根据demo解密消息 public stat ...

  4. 自学Linux Shell11.2-echo命令

    点击返回 自学Linux命令行与Shell脚本之路 11.2-echo命令 echo命令的功能是在显示器上显示一段文字,一般起到一个提示的作用. 语 法:echo [-n][字符串]或 echo [- ...

  5. android progressdialog 对话框试用实例

    ProgressDialog 跟AlertDialog用法差不多,不同的是:ProgressDialog 显示的是一种"加载中"的效果,android 中 ProgressDial ...

  6. [poj2528]Mayor's posters

    题目描述 The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campa ...

  7. [hgoi#2019/2/18]比较水

    T1--调换纸牌(card) Alex有 n张纸牌,每张纸牌上都有一个值ai,Alex把这些纸牌排成一排,希望将纸牌按值从小到大的顺序排好.现在他把这个任务交给你,你只能进行一种操作:选中一张牌,然后 ...

  8. 安装 Minio服务

    #MINIO SERVER Minio是在Apache License v2.0下发布的对象存储服务器.它与Amazon S3云存储服务兼容. 它最适合存储非结构化数据,如照片,视频,日志文件,备份和 ...

  9. C++中const关键字的使用方法,烦透了一遍一遍的搜,总结一下,加深印象!!!

    之前一直在学习C/C++,关于const的使用,这里出现一点,那里出现一点.知识用时方恨少,这一段时间正好各种笔试题,其中关于const的用法也是层出不穷,所以疲于在书本上各种翻,这里汇总一下,加深自 ...

  10. Ubuntu下安装tftp

    用户可以在主机系统联网的情况下,在终端输入下面命令进行安装: vmuser@Linux-host: ~$ sudo apt-get install tftpd-hpa tftp-hpa 配置 TFTP ...