fwxxx
发表于 2020-3-3 20:21:31
zltzlt 发表于 2020-3-3 20:10
解答错误
输入:"aa"
改好了
zltzlt
发表于 2020-3-3 20:22:14
fwxxx 发表于 2020-3-3 20:21
改好了
解答错误
输入:"aaa"
输出:False
预期结果:True
发代码的正确姿势:https://fishc.com.cn/forum.php?mod=viewthread&tid=52272&extra=page%3D1%26filter%3Dtypeid%26typeid%3D441
fan1993423
发表于 2020-3-3 20:25:34
本帖最后由 fan1993423 于 2020-3-3 20:28 编辑
from collections import Counter
def fun342(s):
if len(s)==1:return True
d=list(map(lambda x:x%2,list((Counter(s).values()))))
if d.count(1)==0 or d.count(1)==1:
return True
else:return False
行吧,我一直以为一个字符串没有回文
zltzlt
发表于 2020-3-3 20:26:03
fan1993423 发表于 2020-3-3 20:25
行吧,我一直以为一个字符串没有回文
32 ms
最后的魁拔
发表于 2020-3-3 20:30:04
def f(n):
if len(n)%2==0:
flag = 1
d={}
for i in n:
d = d.get(i,0)+1
for j in d.values():
if j%2==0:
continue
else:
flag = 0
if flag:
return 1
else:
return 0
else:
flag = 0
d={}
for j in n:
d = d.get(j,0)+1
for i in d.values():
if i/2==0:
flag=0
continue
if i%2==1:
flag+=1
if flag<=1:
return 1
else:
return 0
a = input()
if f(a):
print("True")
else:
print("False")
最后一次
zltzlt
发表于 2020-3-3 20:30:45
最后的魁拔 发表于 2020-3-3 20:30
可以了,44 ms
风魔孤行者
发表于 2020-3-3 20:33:02
string = input('请输入字符:')
list1 = []
n=0
while string != '':
list1.append(string.count(string))
string = string.strip(string)
for each in list1:
if each%2 != 0:
n +=1
if n>1:
print('False')
else:
print('True')
总体思路是:计算出输入字符串里每一个字符出现的次数,要达成要求,最多只能有一种字符出现的数量为奇数,剩下的都得为偶数
猫记
发表于 2020-3-3 20:33:28
def f342(s):
s = list(s)
s.sort()
n = 0
i = 0
while i < len(s):
if i == len(s) - 1:
if n == 1:
return 'False'
else:
return 'True'
if s != s:
n += 1
i += 1
else:
i += 2
if n > 1:
return 'False'
return 'True'
print(f342('asdfdsas'))
zltzlt
发表于 2020-3-3 20:34:20
风魔孤行者 发表于 2020-3-3 20:33
string = input('请输入字符:')
list1 = []
1. 请写成一个函数
2. 发代码的正确方法:https://fishc.com.cn/forum.php?mod=viewthread&tid=52272&extra=page%3D1%26filter%3Dtypeid%26typeid%3D441
zltzlt
发表于 2020-3-3 20:34:47
猫记 发表于 2020-3-3 20:33
44 ms
546623863
发表于 2020-3-3 20:37:57
zltzlt 发表于 2020-3-3 20:21
是的
def fun342(s:str):
if(s == ""):
return False
length = len(s)
if(length == 1):
return True
dic = dict()
for index in range(length):
if(s not in dic):
dic] = 1
else:
dic] += 1
top = 0
for value in dic.values():
if(value % 2 == 1):
top += 1
if(top > 1):
return False
else:
pass
if(top <= 1):
return True
else:
return False
行吧
zltzlt
发表于 2020-3-3 20:39:40
546623863 发表于 2020-3-3 20:37
行吧
48 ms
wcshds
发表于 2020-3-3 20:40:27
def test(char):
def even(char):
for each in char:
if char.count(each) % 2 != 0:
return False
else:
return True
if len(char) % 2 == 0:
return even(char)
else:
for each in char:
if char.count(each) % 2 != 0:
return even(char.replace(each, '' , 1))
return False
风魔孤行者
发表于 2020-3-3 20:41:54
zltzlt 发表于 2020-3-3 20:34
1. 请写成一个函数
2. 发代码的正确方法:https://fishc.com.cn/forum.php?mod=viewthread&tid=52272&ex ...
string = input('请输入字符:')
def judge(string):
list1 = []
n=0
while string != '':
list1.append(string.count(string))
string = string.strip(string)
for each in list1:
if each%2 != 0:
n += 1
if n>1:
return False
else:
return True
print(judge(string))
fwxxx
发表于 2020-3-3 20:42:29
def fun(s):
e = []
flag = 0
l = len(s)
if(l%2==0):
for i in s:
if s.count(i)%2 ==0:
continue
else:
return False
return True
if(l%2==1):
for i in s:
if s.count(i)%2==0:
flag+=1
else:
e.append(i)
if(len(set(e))!=1):
return False
returnTrue
if __name__ == '__main__':
s = input()
if(fun(s)):
print("True")
else:
print("false")
zltzlt
发表于 2020-3-3 20:42:49
风魔孤行者 发表于 2020-3-3 20:41
解答错误
输入:"ivicc"
输出:False
预期结果:True
TJBEST
发表于 2020-3-3 20:44:02
马上就来
546623863
发表于 2020-3-3 20:44:33
zltzlt 发表于 2020-3-3 20:39
48 ms
import collections
def fun342(s:str):
if(s == ""):
return False
length = len(s)
if(length == 1):
return True
dic = dict(collections.Counter(s))
top = 0
for value in dic.values():
if(value % 2 == 1):
top += 1
if(top > 1):
return False
else:
pass
return True
换了工具存字典,不知道效率会不会更快一点
zltzlt
发表于 2020-3-3 20:45:48
fwxxx 发表于 2020-3-3 20:42
56 ms{:10_275:}
zltzlt
发表于 2020-3-3 20:46:13
546623863 发表于 2020-3-3 20:44
换了工具存字典,不知道效率会不会更快一点
36 ms