求教 为什么只能输出最后一行 呜呜呜

回复帖子

@zsj1669677544 2019-03-17 20:35 回复

求教 为什么只能输出最后一行 呜呜呜

#include <stdio.h>
#include <stdlib.h>
struct little
{
    int has;
    int times;
};
int main()
{
    struct little a[50];
    for (int i = 0; i < 50; i++)
    {
        a[i].times = 0;
        a[i].has = 0;
    }

    char la[200], lb[200], lc[200], ld[200];
    scanf("%s\n%s\n%s\n%s", la, lb, lc, ld);
    for (int i = 0; la[i] >= 'A' && la[i] <= 'Z'; i++)
        a[la[i] - 'A' + 1].times += 1;
    for (int i = 0; lb[i] >= 'A' && lb[i] <= 'Z'; i++)
        a[lb[i] - 'A' + 1].times += 1;
    for (int i = 0; lc[i] >= 'A' && lc[i] <= 'Z'; i++)
        a[lc[i] - 'A' + 1].times += 1;
    for (int i = 0; ld[i] >= 'A' && ld[i] <= 'Z'; i++)
        a[ld[i] - 'A' + 1].times += 1;
    int j = 0, num = 0;
    for (int i = 1; i <= 26; i++) //j=出现次数最多
    {
        if (a[i].times > j)
            j = a[i].times;
    }
    for (int i = j; j > 0; j--) //j=10=i
    {
        for (int k = 1; k <= 26; k++)
        {
            num = 0;
            if (a[k].times >= i)
            {
                a[k].has = 1;
                num++;
            }
            else
                a[k].has = 0;
        }
        for (int k = 1; k <= 26; k++)
        {
            if (num == 0)
                break;
            if (a[k].has == 0 && num > 0)
                printf("  ");
            if (a[k].has == 1 && num > 1)
            {
                printf("* ");
                num--;
            }
            if (a[k].has == 1 && num == 1)
            {
                printf("*\n");
                num--;
            }
        }
    }
    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");
    system("pause");
    return 0;
反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。