求一批整数中出现最多的数字。输入一个正整数n(1<n≤1000),再输入n个整数,分析每个整数的每一位数字,求出现次数最多的数字。
时间: 2024-06-13 07:07:11 浏览: 128
以下是Python实现求一批整数中出现最多的数字的代码:
```python
n = int(input("请输入正整数n:"))
nums = input("请输入n个整数,用空格隔开:").split()
# 统计每个数字出现的次数
count = {}
for num in nums:
for digit in num:
if digit in count:
count[digit] += 1
else:
count[digit] = 1
# 找出出现次数最多的数字
max_count = 0
max_digit = ''
for digit, c in count.items():
if c > max_count:
max_count = c
max_digit = digit
print("出现次数最多的数字是:", max_digit)
```
输入样例:
```
请输入正整数n:5
请输入n个整数,用空格隔开:123 456 789 12345 67890
```
输出样例:
```
出现次数最多的数字是:3
```
阅读全文