#include<string>
using namespace std;
int main()
{
int count = 0, x = 0;
int num[100] = { 0 }, times[100] = { 0 };
string s;
getline(cin, s);
for (int i = 0; i < s.length(); i++)
{
count = 1;
if (s[i] != ' ')
{
for (int j = 0; j < s.length(); j++)
{
if (i != j && s[j] == s[i])
{
count++;
s[j] = ' ';
}
}
num[x] = s[i];
times[x] = count;
s[i] = ' ';
x++;
}
}
for (int i = 0; i < x - 1; i++)
{
for (int j = i + 1; j < x; j++)
{
if (i != j && num[i] < num[j])
{
int tmp = num[i];
num[i] = num[j];
num[j] = tmp;
int temp = times[i];
times[i] = times[j];
times[j] = temp;
}
}
}
for (int i = 0; i < x; i++)
cout << num[i] << " " << times[i] << endl;
return 0;
}
沒有留言:
張貼留言