HNOJ LOL

来源:互联网 发布:深入java虚拟机 pdf 编辑:程序博客网 时间:2024/06/12 00:59
LOLTime Limit: 1000ms, Special Time Limit:2500ms,Memory Limit:65366KB Problem descriptionYour 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.InputThe 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.OutputFor 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
4fotballsoppingentingspillolje
Sample Output
1230
Judge Tips0 < 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;
}