#include<iostream>#include<vector>#include<ctime>usingnamespace std;intmain(){srand(time(0));int cnt[10]={0};
cout <<"随机100个数字为:\n";for(int i =0; i <100; i ++){int x =rand()%1000;if(i && i %20==0) cout << endl;
cout << x <<" ";
string s =to_string(x);for(auto c : s)
cnt[c -'0']++;}
cout << endl << endl;for(int i =0; i <10; i ++)
cout <<"数字 "<< i <<" 的数量为: "<< cnt[i]<< endl;}
#include<iostream>#include<map>#include<cstring>#include<vector>#include<algorithm>usingnamespace std;intmain(){
string s;
map<string,int> mp;getline(cin,s);for(int i =0; i < s.size(); i ++){if(isalpha(s[i])){int j = i;while(isalpha(s[j])) j ++;
string ss = s.substr(i,j - i);
mp[ss]++;
i = j;}}
vector<pair<int, string>> vec;for(auto it : mp)
vec.push_back({it.second,it.first});sort(vec.begin(),vec.end());for(auto it : vec)
cout << it.second <<" 数量为 : "<< it.first << endl;}