terrortafan 2017-05-19 13:53 采纳率: 0%
浏览 921
已结题

关于航电acm1004总是WA,原题基础上颜色数目相同就按字母序全部输出

感觉结果没毛病啊然鹅T _ T
要求:如果数目相同,按字母序全部输出,每种颜色一行
A test case with N = 0 terminates the input and this test case is not to be processed.

Sample Input:
5
green
red
blue
red
red
3
pink
orange
pink
0
Output:
red
pink

下面是我的代码和运行结果:

 #include<string.h>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0) 
            break;
        char a[1000][16];
        int b[1000]={0};
        char c[16];
        int i,j;
        getchar();
        for(i=1;i<=n;i++)
        {
            gets(a[i]);
        }

        for(i=1;i<=n-1;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                if(strcmp(a[j],a[i])<0)
                {
                    strcpy(c,a[i]);
                    strcpy(a[i],a[j]);
                    strcpy(a[j],c);
                }       
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
                if(strcmp(a[i],a[j])==0)
                b[i]++;
        }
        int max=1,m=1;
        for(i=1;i<=n;i++)
        {
            if(b[i]>max)
            {
                m=i;
                max=b[i];
            }
        }
        if(max==1)
        {
            for(i=1;i<=n;i++)
                cout<<a[i]<<endl;
        }
        else
        {
            cout<<a[m]<<endl;
            for(i=m+1;i<=n;i++)
            {
                if((b[i]==max)&&(strcmp(a[i],a[m])!=0))
                    cout<<a[i]<<endl;
                    m=i;
            }
        }
    }
    return 0;
}

图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-19 16:31
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料