首页 > 试题广场 >

个位数统计 (15)

[编程题]个位数统计 (15)
  • 热度指数:22932 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。

输入描述:
每个输入包含1个测试用例,即一个不超过1000位的正整数N。


输出描述:
对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M。要求按D的升序输出。
示例1

输入

100311

输出

0:2<br/>1:3<br/>3:1
strN = str(input())
strdict ={}
for s in strN:
    if s not in strdict:
        strdict[s]=1
    else:
        strdict[s]+=1
for key in sorted(strdict.keys()):
    print(str(key)+":"+str(strdict[key]))
编辑于 2019-12-15 15:32:04 回复(0)
import collections
D = collections.Counter(input())
L = sorted(zip(D.keys(),D.values()), key = lambda i: i[0])
for i in L:
    print('{}:{}'.format(i[0],i[1]))

编辑于 2019-08-28 09:33:19 回复(0)
num  = list(input())
num_select = list(set(num))#找出里面的非重复的数字
num_select.sort()#排序
for value in num_select:
    print(str(value)+ ':'+ str(num.count(value)))

编辑于 2019-07-18 20:11:01 回复(1)
# -*- coding:utf-8 -*-
from collections import Counter

if __name__ == '__main__':
    num_str = input()
    word_count = dict(Counter(num_str))
    result = sorted(word_count.items(), key=lambda x: x[0])
    for key, val in result:
        print('{}:{}'.format(key, val))
发表于 2019-05-13 13:44:08 回复(0)
st = input()
tongji = [0 for i in range(10)] for i in range(len(st)):
    tongji[int(st[i])] = tongji[int(st[i])] + 1 for i in range(10): if tongji[i] != 0: print(str(i) + ":" + str(tongji[i]))

发表于 2019-03-20 21:24:00 回复(0)
Number = list(str(input()))
count = [0,0,0,0,0,0,0,0,0,0]
for i in Number:
    count[int(i)] += 1
for i in range(10):
    if count[i] > 0:
        print('{0}:{1}'.format(i,count[i]))

发表于 2019-03-08 09:14:16 回复(0)
from collections import Counter
for i,v in sorted(Counter(raw_input()).items()):
      print '%s:%d'%(i,v)
发表于 2019-01-11 17:58:19 回复(0)
#python 两行解法
a=input()
for n in range(10):(print(str(n)+':'+str(a.count(str(n)))))if (int(a.count(str(n)))!=0) else ''
发表于 2018-11-07 19:58:35 回复(0)
number=raw_input()
times={}
for s in number:
    if s not in times:
        times[s]=1
    else:
        times[s]+=1
for i in range(10):
    if str(i) in times:
        print '%s:%s'%(i,times[str(i)])

发表于 2018-01-05 11:38:10 回复(0)

python三行解法:

from collections import Counter
a=sorted(Counter(input()).items(),key=lambda c:c[0])
for i in a:print(str(i[0])+":"+str(i[1]))
发表于 2017-10-09 11:03:13 回复(4)
 from collections import Counter
try:
    while True:
        counter = Counter(raw_input())
        counter_list = counter.most_common()
        counter_list.sort()
        for each in counter_list:
            print each[0] + ':' + str(each[1])
except EOFError:
    pass
人生苦短,我用Python
发表于 2016-11-03 16:22:38 回复(0)
from collections import Counter
try:
    while True:
        counter = Counter(raw_input())
        counter_list = counter.most_common()
        counter_list.sort()
        for each in counter_list:
            print each[0] + ':' + str(each[1])
except EOFError:
    pass
人生苦短,我用Python
发表于 2016-11-02 23:27:11 回复(0)

问题信息

难度:
12条回答 23615浏览

热门推荐

通过挑战的用户