VJ_判断数字个数_map

判断一行字符串中的数字出现的个数。

Input

输入有多行,每行一个字符串,该字符串中可以包含&^$^#@*任何符号以及空格。

Output

有多行。输出该字符串中每个出现过的数字,然后在冒号“:”后面输出该数字出现的次数。按数字大小,从小到大的顺序输出。一行输出一个数字及其出现次数。没有出现过的数字不输出。

Sample

Inputcopy Outputcopy
ldksfj857ld*&%&^%00000
138****0055end
0:5
5:1
7:1
8:1
0:2
1:1
3:1
5:2
8:1

//
#include<bits/stdc++.h>
using namespace std;

map<char,int> mp;
map<char,int>::iterator it;

int main()
{
    string s;
    int i;

    while( getline( cin,s ) )
    {
        mp.clear();
        for( i=0;i<s.size();i++ )
            if( isdigit( s[i] ) ) mp[ s[i] ]++;

        for( it=mp.begin();it!=mp.end();it++ )
        {
            cout<<it->first<<":"<<it->second<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/125135166
vj
今日推荐