python 牛客真題 統計迴文
s=input()
t=input()
def judge(s):
ls=len(s)
for i in range(ls//2):
if s[i] != s[ls-1-i]:
return False
return True
cnt=0
for i in range(len(s)+1):
if judge(s[:i]+t+s[i:]): cnt+=1
print(cnt)
相關推薦
python 牛客真題 統計迴文
s=input() t=input() def judge(s): ls=len(s) for i in range(ls//2): if s[i] != s[ls-1-i]: return False return True
python 牛客真題 合唱團
n=int(input()) performance=list(input().split()) kd=list(input().split()) k=int(kd[0]) d=int(kd[1]) dp=[[0]*n for _ in range(k)] dp1=[[0]*n for _
python 牛客真題 不要二
num=input().split() n=int(num[0]) m=int(num[1]) if m%4==2: m,n=n,m tmp1=(m+1)//2 tmp2=m-tmp1 mysum=0 for i in range(n): if i%4==0 or i%4==
python 牛客真題 幸運的袋子
DFS,需要剪枝 n=int(input()) num=list(map(int,input().split())) num.sort() def dfs(num,mysum,mymul): count=0 for i in range(len(num)):
python 牛客真題 混合原料
一道很讚的題目。遵循這樣一個最基本的思路,最大的數肯定不能通過異或生成,所以必須要取。遵循這個思路:除了這個最大的數其他所有與其位數相同的數都可以通過異或生成。再看異或這個操作本身的特殊性(不同為1,相同為0)即意味著如果最大的數的位數為4,那麼肯定要取到位數為3的最大數。 n=int(
python 牛客真題 數列還原
考察全排列? nk=list(input().split()) n=int(nk[0]) k=int(nk[1]) num=[int(c) for c in list(input().split())] m=[0]*(n+1) index=[] for i in range(n):
python 牛客真題 藏寶圖
s=input() t=input() l1=len(s) l2=len(t) i,j=0,0 while i<l1 and j<l2: if s[i]==t[j]: i+=1 j+=1 else: i+=1 if
python 牛客真題 分蘋果
改成 只能往相鄰移動的話難度會增加 n=int(input()) num=[int(c) for c in input().split()] if sum(num)%n !=0: print(-1) else: target=sum(num)//n flag =
python 牛客真題 分田地
二分貪心查詢 nm=list(input().split()) n=int(nm[0]) m=int(nm[1]) board=[[0]*m for _ in range(n)] count=0 while count<n: num=input() for j in
牛客練習賽30-A-迴文日期(構造)
題目描述 眾所周知,小K是nowcoder的暴政苟管理,所以小K很擅長踢樹,雖然本題與踢樹無關 小K喜歡將日期排列成yyyy-mm-dd的形式(位數不足添零補齊)的形式,雖然這與小K只會做迴文字串這道水題無關,但小K覺得日期組成的迴文串也是挺可愛的。作為一個涼心出題
python 牛客 迴文序列
n=int(input()) num=list(map(int,input().split())) cnt=0 p=0 q=n-1 lft=num[0] rht=num[n-1] while p<q: if lft==rht: p+=1 q-=1
備戰藍橋杯(真題)第五屆第三題(迴文素數)
迴文素數10301是個5位的素數。它有個特點,把數字倒過來還是它本身,具有這樣特徵的素數,我們稱之為:迴文素數。105011060111311這些都是5位的迴文素數。請你計算一下,像這樣的5位數的迴文素數,
網易2017秋招程式設計題:迴文序列 [python]
''' [程式設計題] 迴文序列 時間限制:1秒 空間限制:32768K 如果一個數字序列逆置之後跟原序列是一樣的就稱這樣的數字序列為迴文序列。例如: {1, 2, 1}, {15, 78, 78, 15} , {112} 是迴文序列, {1, 2, 2}, {15, 7
數串——牛客刷題
拼接 public 最大整數 sys tint 比較 ont min 16px 題目描述: 設有n個正整數,將他們連接成一排,組成一個最大的多位整數。 如:n=3時,3個整數13,312,343,連成的最大整數為34331213。 如:n=4時,4個整數7,13,4,2
句子反轉——牛客刷題(java)
++ () ring system for 字母 ext style scan 題目描述: 給定一個句子(只包含字母和空格), 將句子中的單詞位置反轉,單詞用空格分割, 單詞之間只有一個空格,前後沒有空格。 比如: (1) “hello xiao mi”-> “mi
牛客刷題day04
描述: 輸入一個整數,將這個整數以字串的形式逆序輸出 程式不考慮負數的情況,若數字含有0,則逆序形式也含有0,如輸入為100,則輸出為001 import java.util.Scanner; public class Main { public static void main(
C和指標--程式設計題9.14第10小題--判斷迴文函式
題目: 編寫函式 int palindrom( char *string); 如果引數字串是個迴文,函式就返回真,否則就返回假。迴文就是指一個字串從左向右讀和從右向左讀是一樣的。函式應忽略所有的非字母字元,而且在進行字元比較時不用區分大小寫。 前提是空白字元、標點符號和大小寫狀態被忽略,當Adam
計算機考研複試真題 統計單詞
題目描述 編一個程式,讀入使用者輸入的,以“.”結尾的一行文字,統計一共有多少個單詞,並分別輸出每個單詞含有多少個字元。 (凡是以一個或多個空格隔開的部分就為一個單詞) 輸入描述: 輸入包括1行字串,以“.”結束,字串中包含多個單詞,單詞之間以一個或多個空格隔開。 輸出描述:
牛客66題(8)跳臺階
一隻青蛙一次可以跳上1級臺階,也可以跳上2級。求該青蛙跳上一個n級的臺階總共有多少種跳法(先後次序不同算不同的結果)。 假設有1階有1種方法; 假設有2階有2種方法; 假設有3階有(2,1),(1,2),(1,1,1)3種方法; 假設有4階(1,1,1,1)(2,1,1)(1,2,1
牛客66題(7)斐波那契數列
大家都知道斐波那契數列,現在要求輸入一個整數n,請你輸出斐波那契數列的第n項(從0開始,第0項為0)。 n<=39;斐波那契數列特徵為除第一項與第二項外其餘項均為前兩項的和。 class Solution { public: int Fibonacci(int n) {