HNOJ LOL

LOL
Time Limit: 1000ms, Special Time Limit:2500ms,Memory Limit:65366KB
 
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.)
Problem Source

IDIOPEN 2011

 

题目思路:只要查找字符子串,再处理就OK的了

 

program:

 

 

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
char ch[55];
int main()
{
int test;
cin>>test;
while(test--)
{
   cin>>ch;
   if(strlen(ch)==1)
      {
        if(ch[0]=='l'||ch[0]=='o')
          {
           cout<<2<<endl;
            continue;
          }
        else
          {
             cout<<3<<endl;
             continue;
          }
                    
      }
   char *p;
   char a[5]={"lol"},b[5]={"lo"},c[5]={"ol"},d='l',e='o',f[5]={"ll"};
   p=strstr(ch,a);
   if(p)
     {
         cout<<0<<endl;
         //cout<<"---------1"<<endl;
         continue;
     }
   p=strstr(ch,b);//
   if(p)
     {
         cout<<1<<endl;
         //cout<<"---------2"<<endl;
         continue;
     }
   p=strstr(ch,c);//
   if(p)
     {
         cout<<1<<endl;
         //cout<<"---------3"<<endl;
         continue;
     }
   p=strstr(ch,f);//
   if(p)
     {
         cout<<1<<endl;
         //cout<<"---------4"<<endl;
         continue;
     }
   for(int i=0;i<(strlen(ch)-2);i++)
    {
       if(ch[i]=='l'&&ch[i+2]=='l')
        {
           cout<<1<<endl;
          // cout<<"---------5"<<endl;
           goto end;
        }    
    }
   
   p=strchr(ch,d);/
   if(p)
     {
         cout<<2<<endl;
         //cout<<"---------6"<<endl;
         continue;
     }
   p=strchr(ch,e);/
   if(p)
     {
         cout<<2<<endl;
         //cout<<"---------7"<<endl;
         continue;
     }
   cout<<3<<endl;
   
 end:;             
}
//system("pause");
return 0;
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值