马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
// https://www.luogu.com.cn/problem/P1598
#include <iostream>
#include <string>
using namespace std;
string del_char(string str, char ch)
{
int i;
string s = "";
for (i = 0; i < str.size(); i++)
{
if (str[i] != ch)
s += str[i];
}
return s;
}
int count(string str, char ch)
{
int i, r = 0;
for (i = 0; i < str.size(); i++)
{
if (str[i] == ch)
{
r++;
}
}
return r;
}
int max(int *array, int len)
{
if (len == 0)
return 0;
else if (len == 1)
return array[0];
else if (len == 2)
return array[0] > array[1] ? array[0] : array[1];
int i = 1, max_val = array[0];
for (; i < len; i++)
{
if (array[i] > max_val)
{
max_val = array[i];
}
}
return max_val;
}
int main()
{
string t, a, b, c, d;
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int arr[26], i, j;
getline(cin, a);
getline(cin, b);
getline(cin, c);
getline(cin, d);
t = del_char(a + b + c + d, ' ');
for (i = 0; i < 26; i++)
{
arr[i] = count(t, alpha[i]);
}
for (i = max(arr, 26); i >= 0; i--)
{
if (i == 0)
cout << "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
else
{
for (j = 0; j < 26; j++)
{
if (arr[j] >= i)
{
cout << "*";
}
else
{
cout << " ";
}
if (j != 25)
cout << " ";
}
cout << endl;
}
}
return 0;
}
|