鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: 新手·ing

[已解决]Python:每日一题 155(高额悬赏)

[复制链接]
发表于 2018-3-9 11:09:13 | 显示全部楼层
lin193556271 发表于 2018-3-4 08:11
xuzu = [1,2,3,4,5,6,7,8]
for i in range(1,101):
    if i in xuzu:

最佳答案看不懂,能否解释一下~求高手解答~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-3-9 11:38:44 | 显示全部楼层
graceasyi 发表于 2018-3-9 11:09
最佳答案看不懂,能否解释一下~求高手解答~

就是字面意思。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-4-23 23:08:44 | 显示全部楼层
#题目:一个无序数组里有99个不重复正整数,范围从1到100,唯独缺少一个整数。如何找出这个缺失的整数?
我们假如已经得到了这个数组a[.......]
number = 5050 - sum(a)
第二第三问
假设我们已经有这个数组a[...............]
number = 0
for i in range(1,101):
        for temp in a:
                if i == temp:
                        number+=1
        if number%2 != 0:
                print('temp')
谢谢楼主的题目,不知道自己对不对但是思考了很久学到了不少东西。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-13 13:06:14 | 显示全部楼层
#原题
list1=list(range(1,100))   #生成一个1~99的列表,缺少整数100
print(5050-sum(list1))

#原题拓展
list2=[1,1,2,2,5,5,5]
for i in set(list2):
    if list2.count(i)%2==1:  #i元素出现奇数次
        print(i)
        break
   
#原题拓展二
list2=[1,1,2,2,5,5,5,6,6,12]
count=0
for i in set(list2):
    if list2.count(i)%2==1:  #i元素出现奇数次
        count+=1             #count用来统计找到了几个符合要求的数
        print(i)
        if count==2:
            break  
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-17 14:03:27 | 显示全部楼层
本帖最后由 DavidCowboy 于 2018-8-17 14:43 编辑

題目一
list1 = [0,1,2,3,5,6,7,8,9]

for x in range(10):
    if x not in list1:
        print(x)

題目二
list1 = [0,0,1,1,2,2,3,3,4,4,4,5,5,6,6,7,7,8,8,9,9]
list2 = []

for x in range(len(list1)):
    count = 0
    for y in range(len(list1)):
        if list1[x] == list1[y]:
            count += 1
    list2.append([list1[x] , count])

for z in range(10):
    if list2[z][1] %2 != 0:
        print(list2[z][0])
        break

題目三
list1 = [0,0,1,1,2,2,3,3,4,4,4,4,4,5,5,6,6,6,7,7,8,8,9,9]
list2 = []

for x in range(len(list1)):
    count = 0
    for y in range(len(list1)):
        if list1[x] == list1[y]:
            count += 1
    list2.append([list1[x] , count])

for z in range(len(list2)):
    if list2[z][1] %2 == 1:
        print(list2[z][0])
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-23 17:05:46 | 显示全部楼层
不懂方法,只能硬算了
  1. #扩展题目 一个函数解决
  2. def fun_155(list1):
  3.     while True:
  4.         m=len(list1)
  5.         try:
  6.             for i in set(list1):
  7.                 list1.remove(i)
  8.                 list1.remove(i)
  9.         except:
  10.             print(i,end=' ')
  11.         if m==len(list1):
  12.             break
  13.     print()
  14. fun_155([1,1,2,2,3,3,4,5,5])
  15. fun_155([1,1,2,2,3,4,5,5])
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-7-28 13:36:51 | 显示全部楼层
本帖最后由 永恒的蓝色梦想 于 2019-9-6 21:30 编辑
  1. l=[18, 80, 43, 64, 56, 92, 7, 98, 27, 83, 36, 30, 87, 32, 49, 35, 63, 37, 26, 9, 42, 82, 40, 53, 84, 72, 78, 34, 10, 81, 69, 100, 28, 93, 75, 54, 97, 76, 8, 50, 65, 90, 61, 38, 47, 25, 6, 60, 67, 86, 99, 12, 24, 31, 88, 94, 91, 74, 59, 79, 48, 23, 73, 11, 45, 20, 1, 57, 5, 16, 55, 70, 85, 77, 19, 71, 58, 4, 29, 3, 15, 14, 95, 41, 13, 33, 39, 52, 46, 62, 2, 44, 66, 17, 21, 96, 68, 51, 89]
  2. for i in range(1,101):
  3.         if i not in l:
  4.                 print(i)
  5.                 break
  6. #-------------------------------------------------
  7. l=[75, 8, 55, 81, 45, 28, 67, 2, 60, 33, 63, 75, 13, 53, 61, 69, 98, 49, 84, 41, 83, 20, 67, 88, 100, 29, 25, 15, 15, 70, 63, 89, 91, 81, 86, 51, 97, 5, 62, 52, 99, 14, 64, 84, 82, 76, 54, 100, 96, 71, 33, 8, 65, 22, 37, 85, 51, 44, 18, 92, 58, 30, 17, 7, 42, 77, 43, 40, 94, 89, 17, 35, 25, 4, 96, 4, 73, 26, 50, 46, 19, 5, 82, 60, 99, 47, 11, 36, 40, 34, 95, 11, 78, 55, 58, 59, 92, 72, 54, 74, 73, 3, 52, 9, 68, 36, 10, 70, 38, 68, 16, 77, 42, 50, 53, 69, 94, 16, 23, 90, 80, 65, 56, 49, 95, 14, 32, 87, 24, 76, 18, 57, 20, 7, 22, 39, 78, 32, 12, 93, 86, 9, 31, 19, 23, 88, 3, 61, 91, 31, 38, 30, 74, 71, 44, 72, 66, 28, 1, 34, 1, 93, 90, 45, 29, 47, 48, 98, 21, 62, 24, 27, 46, 26, 87, 13, 6, 6, 97, 57, 79, 48, 79, 12, 41, 64, 21, 85, 10, 37, 83, 39, 27, 80, 59, 2, 56, 66, 43]
  8. from functools import reduce
  9. reduce(lambda x,y:x^y,l,default=0)
  10. #-------------------------------------------------
  11. l=[75, 8, 55, 81, 45, 28, 67, 2, 60, 33, 63, 75, 13, 53, 61, 69, 98, 49, 84, 41, 83, 20, 67, 88, 100, 29, 25, 15, 15, 70, 63, 89, 91, 81, 86, 51, 97, 5, 62, 52, 99, 14, 64, 84, 82, 76, 54, 100, 96, 71, 33, 8, 65, 22, 37, 85, 51, 44, 18, 92, 30, 17, 7, 42, 77, 43, 40, 94, 89, 17, 35, 25, 4, 96, 4, 73, 26, 50, 46, 19, 5, 82, 60, 99, 47, 11, 36, 40, 34, 95, 11, 78, 55, 58, 59, 92, 72, 54, 74, 73, 3, 52, 9, 68, 36, 10, 70, 38, 68, 16, 77, 42, 50, 53, 69, 94, 16, 23, 90, 80, 65, 56, 49, 95, 14, 32, 87, 24, 76, 18, 57, 20, 7, 22, 39, 78, 32, 12, 93, 86, 9, 31, 19, 23, 88, 3, 61, 91, 31, 38, 30, 74, 71, 44, 72, 66, 28, 1, 34, 1, 93, 90, 45, 29, 47, 48, 98, 21, 62, 24, 27, 46, 26, 87, 13, 6, 6, 97, 57, 79, 48, 79, 12, 41, 64, 21, 85, 10, 37, 83, 39, 27, 80, 59, 2, 56, 66, 43]
  12. time=0
  13. for i in set(l):
  14.         if time>2:break
  15.         if l.count(i)%2!=0:
  16.                 print(i)
  17.                 time+=1
复制代码

异或算法分治法都不会,直接暴力了
研究了一下异或,改了一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-25 03:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表