2018年湘潭大学程序设计竞赛 B String

题目链接点击打开链接

这个题 其实 读懂 题意后很简单的 大意就是问你 6*6的正方形 再给你一串字符串 然后让你输出行列都是出现次数最多的字符,这个本身来说就是简单的 难的地方应该是  读题  代码如下

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <string>
using namespace std;
char p[10][10]={"012345","6789AB","CDEFGH","IJKLMN","OPQRST","UVWXYZ"};
char pp[1000];
int h[10],l[10];
int main()
{
     char ss;
     int t,len,maxl,maxh;
     queue<char>aa;
     scanf("%d",&t);
     while(t--)
     {
        maxl=maxh=0;
        memset(h,0,sizeof(h));
        memset(l,0,sizeof(l));
        scanf("%s",pp);
        len=strlen(pp);
        for(int i=0;i<6;i++)
        {
             for(int j=0;j<6;j++)
             {
                  for(int k=0;k<len;k++)
                  {
                       if(p[i][j]==pp[k])
                       {
                             h[i]++;
                             l[j]++;
                             maxl=max(maxl,l[j]);
                             maxh=max(maxh,h[i]);
                       }
                  }
             }
        }
        for(int i=0;i<6;i++)
        {
             for(int j=0;j<6;j++)
             {
                  if(l[j]==maxl&&h[i]==maxh)
                    aa.push(p[i][j]);
             }
        }
         while(!aa.empty())
         {
               ss=aa.front();
               aa.pop();
               printf("%c",ss);
         }
         printf("\n");
     }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41071646/article/details/80219497