This commit is contained in:
NaiJi ✨ 2024-04-30 11:50:38 +04:00
parent 68a7e906b6
commit ad9e7158da
1 changed files with 61 additions and 22 deletions

View File

@ -1,32 +1,71 @@
#include <stdio.h> #include <stdio.h>
#define MAX_AMOUNT_OF_LENGTHS 256
main() main()
{ {
int c, i, nwhite, nother; int c, i, j;
int ndigit[10]; int current_length, max_length;
int nlengths[MAX_AMOUNT_OF_LENGTHS];
nwhite = nother = 0; for (i = 0; i < MAX_AMOUNT_OF_LENGTHS; ++i)
for (i = 0; i < 10; ++i) nlengths[i] = 0;
ndigit[i] = 0;
current_length = max_length = 0;
while ((c = getchar()) != EOF) while ((c = getchar()) != '\n')
if (c >= '0' && c <= '9') {
++ndigit[c-'0']; if (c == '\n' || c == ' ' || c == '\t')
else if (c == ' ' || c == '\t')
++nwhite;
else if (c == '\n')
{ {
++nwhite; ++nlengths[current_length];
printf("digits = "); if (current_length > max_length)
for (i = 0; i < 10; ++i) max_length = current_length;
printf(" %d", ndigit[i]); current_length = 0;
printf(", white space = %d, other = %d\n", nwhite, nother);
} }
else else
++nother; {
++current_length;
}
}
printf("digits = "); ++nlengths[current_length];
for (i = 0; i < 10; ++i) if (current_length > max_length)
printf(" %d", ndigit[i]); max_length = current_length;
printf(", white space = %d, other = %d\n", nwhite, nother);
printf("horizonal:\n");
for (i = 1; i < MAX_AMOUNT_OF_LENGTHS; ++i)
{
int counter = nlengths[i];
if (counter > 0)
{
printf("%d: ", i);
while (counter > 0)
{
--counter;
printf("*");
}
printf("\n");
}
}
printf("\n\nvertical:\n");
for (j = max_length; j > 0; --j)
{
for (i = 1; i < MAX_AMOUNT_OF_LENGTHS; ++i)
{
if (nlengths[i] > 0)
{
if (nlengths[i] >= j)
printf("*");
else
printf(" ");
}
}
printf("\n");
}
for (i = 1; i < MAX_AMOUNT_OF_LENGTHS; ++i)
{
if (nlengths[i] > 0)
printf("%d", i);
}
printf("\n");
} }