poj1598(字符串处理)

从早上9点搞到现在:

总结几点 1:要保证输出顺序不便

2:吸收多余空格;

3:题目最后一行输出有问题直接用EOF结束

4:key (aba) aaba...aba....abaaba....答案是一;

5:注意循环不要有死循环;




#include <iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#include<map>
#include<list>
#include<set>
#define INF 1<<28

using namespace std;

struct node
{
    int sum,no;
    char  s[200];
    char s1[200];
} str1[220];

char str[220][200];
int n,k,Case=1;

void  pb(int i)
{
    for(int j=0;str1[i].s1[j]!='\0';j++)
    {
        for(int l=0;l<n;l++)
        {
            int f=1,m;
            for( m=0;str[l][m]!='\0';m++)
                if(str[l][m]!=tolower(str1[i].s1[j+m]))
            {
                f=0;
                break;
            }
            if(f==1&&((j==0&&(!isalpha(str1[i].s1[j+m])))||(j!=0&&(!isalpha(str1[i].s1[j-1]))&&(!isalpha(str1[i].s1[j+m])))))
            {
                      str1[i].sum++;
//                      printf("m1=%c\n",str1[i].s1[j-1]);
//                      printf("m=%c\n",str1[i].s1[j+m]);
            }
        }
    }
}
int  cmp( void const *a, void  const *b)
{
    struct node *aa=( node*) a;
    struct node *bb=( node*)  b;
    if((bb->sum)==(aa->sum))
        return (aa->no)-(bb->no);
    return  (bb->sum)-(aa->sum);
}
int main()
{

    while(scanf("%d%d",&n,&k)!=EOF)
    {
        memset(str1,0,sizeof(str1));
        memset(str,0,sizeof(str));
        for(int i=0; i<n; i++)
        {
            scanf(" %s",str[i]);
//            for(int j=0;str[i][j]!='\0';j++)
//                str[i][j]=tolower(str[i][j]);
        }
        getchar();
        for(int i=0; i<k; i++)
        {

            int t=0,l=0;
            while(1)
            {
                char c;
                c=getchar();

                if(c=='\n'||c==EOF)  break;
                str1[i].s1[l++]=c;
                if(islower(c))  str1[i].s[t++]=c;
                else if(isupper(c))  str1[i].s[t++]=tolower(c);
            }
            str1[i].s[t]='\0';
            str1[i].sum=0;
            str1[i].no=i;
            str1[i].s1[l]='\0';
            pb(i);
        }
        qsort(str1,k,sizeof(str1[0]),cmp);
//        for(int i=0;i<k;i++)
//            printf("%d  ",str1[i].sum);
        int MAX=str1[0].sum;
        int t=1;
        printf("Excuse Set #%d\n",Case);
        Case++;
        printf("%s\n",str1[0].s1);
        while(str1[t].sum==MAX&&t<k)
        {
            printf("%s\n",str1[t].s1);
            t++;
        }
        printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值