找出字串中缺失字母,並按字母順序排序輸出

2021-10-13 19:00:43 字數 1562 閱讀 5169

全字母短句 pangram 是包含所有英文本母的句子,比如:a quick brown fox jumps over the lazy dog. 定義並實現乙個方法 get_missing_letter, 傳入乙個字串採納數,返回引數字串變成乙個 pangram 中所缺失的字元。應該忽略傳入字串引數中的大小寫,返回應該都是小寫字元並按字母順序排序(請忽略所有非 acsii 字元)

下面示例是用來解釋,雙引號不需要考慮:

(0)輸入: 「a quick brown fox for jumps over the lazy dog」

返回: 「」

(1)輸入: 「a slow yellow fox crawls under the proactive dog」

返回: 「bjkmqz」

(2)輸入: 「lions, and tigers, and bears, oh my!」

返回: 「cfjkpquvwxz」

(3)輸入: 「」

返回:「abcdefghijklmnopqrstuvwxyz」

import string

tem = string.ascii_lowercase

defget_missing_letter

(s):

#考慮重複字母

res =

""for i in tem:

if i not

in s:

res += i

print

(res)

get_missing_letter(

"a quick brown fox for jumps over the lazy dog"

)get_missing_letter(

"a slow yellow fox crawls under the proactive dog"

)get_missing_letter(

"lions, and tigers, and bears, oh my!"

)get_missing_letter(

"")

import string

tem = string.ascii_lowercase

defget_missing_letter

(s):

res =

set(tem)

-set

(s)print(""

.join(

sorted

(res)

))

get_missing_letter(

"a quick brown fox for jumps over the lazy dog"

)get_missing_letter(

"a slow yellow fox crawls under the proactive dog"

)get_missing_letter(

"lions, and tigers, and bears, oh my!"

)get_missing_letter(

"")

找出字串

有乙個排過序的字串陣列,但是其中有插入了一些空字串,請設計乙個演算法,找出給定字串的位置。演算法的查詢部分的複雜度應該為log級別。給定乙個string陣列str,同時給定陣列大小n和需要查詢的string x,請返回該串的位置 位置從零開始 測試樣例 a b c d 6,c 返回 3 思路 二分查...

找出字串

有乙個排過序的字串陣列,但是其中有插入了一些空字串,請設計乙個演算法,找出給定字串的位置。演算法的查詢部分的複雜度應該為log級別。給定乙個string陣列str,同時給定陣列大小n和需要查詢的string x,請返回該串的位置 位置從零開始 測試樣例 a b c d 6,c 返回 3 解題思路 二...

正則妙用,找出字串的的數字 中文 字母

public static void main string args throws exception list 思路 將字串按查詢型別拆分獲得陣列,計算陣列長度。list list 注意 public string split charsequence input,int limit 其中 li...