纯 C![](//图.tk/1)
by ACPC @ 2023-08-08 13:30:47
换成 fgets 读入过了,奇怪,为什么 getchar 读入就会超时
```c
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
int main()
{
// 读入 4 行字符串,并统计每个字母出现次数,最大出现次数记为 max,最后一次出现记为 last
int count[26] = { 0 }, max = 0, i = 0, j = 0, last = 0;
char tmp[111] = { 0 };
for (i = 0; i < 4; i++)
{
fgets(tmp, 110, stdin);
for (j = 0; j < strlen(tmp); j++)
{
if (tmp[j] >= 'A' && tmp[j] <= 'Z')
{
count[tmp[j] - 'A']++;
if (count[tmp[j] - 'A'] > max)
{
max = count[tmp[j] - 'A'];
last = tmp[j] - 'A';
}
}
}
}
// 打印非最后一行
for (i = max; i >= 1; i--)
{
// 统计每一行的星号最后出现的位置 last
for (j = last; j < 26; j++)
{
if (count[j] >= i)
{
last = j;
}
}
// 打印每行非最后一个
for (j = 0; j < last; j++)
{
if (count[j] >= i)
{
printf("* ");
}
else
{
printf(" ");
}
}
// 打印每行最后一个,特殊处理
printf("*\n");
}
// 打印最后一行
printf("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\n");
return 0;
}
```
by Jumpy @ 2023-08-08 13:43:34