湖南大学 oj LOL 字符处理函数 strstr 的应用

本文深入探讨了AI音视频处理技术,包括视频分割、语义识别、自动驾驶、AR、SLAM、物体检测识别、语音识别变声及终端AI边缘计算等领域的最新发展和应用案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://acm.hnu.cn/online/?action=problem&type=show&id=12512

LOL
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65366KB
Total submit users: 30, Accepted users: 28
Problem 12512 : No special judgement
Problem description
Your friend Andreas has a very good sense of humour. In fact, it is so good that he even enjoys to change words so that they will contain the substring lol. For example,during the 2010 FIFA World Cup in soccer he had much fun changing the word fotball to fotbalol. In order to be more ecient in his word plays, he has asked you to make a computer program that nds the minimum number of changes needed in order to transform a string into a new string containing lol as a substring. There are three legal ways to change a string: delete a character, insert a new character and replace an existing character with a new one.
Input
The first line of the input consists of a single number T, the number of test cases. Then follows T lines, containing a string S consisting of lower case letters between a and z only.
Output
For each string, output on its own line the minimum number of changes needed in order to obtain a string containing lol as a substring.
Sample Input
4
fotball
sopp
ingenting
spillolje
Sample Output
1
2
3
0
Judge Tips
0 < T <= 100 0 < |S| <= 50 (That is, the maximal string length is 50.)
要注意的是strstr函数的用法 它在库函数  string.h  里面,这样更加的简单。

char *p ,a[100],b[20];

p=strstr(a,b);

若在a中找到了b,返回的是他们中的地址;

若没有找到 返回的是NULL。

要善于利用库函数。

算法 : 题意就是 将字符串通过 插入,删除,替换使之字符串里面包含 lol这个字串。

三个一组进行查找

1有 lol的 操作步骤为0

2有lo ,ol ,ll ,l@l的操作步骤为1  @代表的是任意字符除了o。

3   1,2步不成立的话,若字符里面包含l或o的话 操作步骤为2 若不包含的话操作不走为3。


post code:

#include<stdio.h>
#include<string.h>
int main()
{
    char a[200];
    char lol[5]="lol", lo[5]="lo" ,ol[5]="ol", ll[5]="ll";
    int t;
    scanf("%d",&t);getchar();
    while(t--)
    {
        char *p=NULL;
        gets(a);
        p=strstr(a,lol); if(p!=NULL){printf("0\n");continue;}//第一步操作
        p=strstr(a,lo);  if(p!=NULL){printf("1\n");continue;}//第二步操作
        p=strstr(a,ol);  if(p!=NULL){printf("1\n");continue;}      
        p=strstr(a,ll);  if(p!=NULL){printf("1\n");continue;}                
        
        int len,i,flag=0;
        
        len=strlen(a);
        
        for( i=0; i<len-2; i++ )   //查找l@l的操作
        {
            if(a[i]=='l'&&a[i+2]=='l'){
                                     printf("1\n");
                                     flag=1;
                                     break;
                                     }   
        }  
        
        if(flag==1)continue;
        
        int sum=0;
        for( i=0; i<len; i++)  //bu
        {
         if(a[i]=='l'||a[i]=='o'){sum++;break;}     
        }
        if(sum==1)printf("2\n");
        else printf("3\n");  
              
    }
          
    
    
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值