鱼C论坛

 找回密码
 立即注册
查看: 2117|回复: 2

[已解决]整数的个数:输入格式怎么表示

[复制链接]
发表于 2020-12-6 10:05:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
help.jpg
  1. num = input("")
  2. x = []
  3. count1 = 0
  4. count5 =0
  5. count10 =0
  6. for i in range(int(num)):
  7.     teep = input("")
  8.     x.append(teep)
  9. for j in range(int(num)):
  10.     if j == 1:
  11.         count1 += 1
  12.     elif j == 5:
  13.         count5 += 1
  14.     elif j ==10:
  15.         count += 1
  16. print(count1)
  17. print(count5)
  18. print(count10)
复制代码


这个输入的格式怎么搞啊。。。不太会
最佳答案
2020-12-6 10:34:08
  1. k = input('')
  2. temp = input('')

  3. lst = [int(i) for i in temp.split(' ')]
  4. print(lst.count(1),lst.count(5),lst.count(10),sep='\n')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-12-6 10:27:49 | 显示全部楼层
字符串分割
  1. k = int(input())
  2. n1, n5, n10 = 0, 0, 0
  3. list1 = list(map(int, (input()).split(" "))) #映射为int类型
  4. for i in range(len(list1)):
  5.     if(list1[i] == 1):
  6.         n1 += 1
  7.     if(list1[i] == 5):
  8.         n5 += 1
  9.     if (list1[i] == 10):
  10.         n10 += 1
  11. print(n1, n5, n10)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-6 10:34:08 | 显示全部楼层    本楼为最佳答案   
  1. k = input('')
  2. temp = input('')

  3. lst = [int(i) for i in temp.split(' ')]
  4. print(lst.count(1),lst.count(5),lst.count(10),sep='\n')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-30 20:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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