BZOJ2295我愛你啊

2295: 【POJ Challenge】我愛你啊
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 202 Solved: 140
Description
ftiasch是個十分受女生歡迎的同學,所以她總是收到許多情書。雖然她十分有魅力,然而她卻是個低調的人。因此她從來不會告訴別人她到底收到了多少情書。
ftiasch的好朋友1tthinking想知道她到底收到了多少情書。1tthinking知道,ftiasch每次收到一封情書,就會在日記最後寫下一個包含”luvletter”子序列的串。比如現在ftiasch的日記是alduddvdletterflusvletetedr,那麼ftiasch可能受到了0、1、2封情書。現在給出一些ftiasch的日記,問對於每篇日記,ftiasch最多可能受到多少的情書。
某個序列的子序列是從最初序列通過去除某些元素但不破壞餘下元素的相對位置而形成的新序列。參考wikipedia。
這裏寫圖片描述
Input
第1行,一個整數 T (0 ≤ T ≤ 100), 日記的數量。
第2到 T + 1行,ftiasch的日記 (只包含’a’-‘z’ 和空格, 長度小於100001)
Output
第1到T行,一個整數, 最大可能的情書數量。
Sample Input
5
t
llllluvletterrr
luvletterlauavalaeatataearaluvletter
is wzk a famous boy yes buz he always receives a lot of luv letters
my heart beats her waves at the shore of the world and writes upon it her signature in tears with the words i love thee
Sample Output
0
1
3
1
0
很奇怪的是,這個人是女同學,爲什麼會收到女生寫的情書233
簡單模擬。。
附上本蒟蒻的代碼:

#include<cstdio>
#include<cstring>
using namespace std;
int T,i,ans=0,tot,j;
char s[100001],h[10]="luvletter";

int read()
{
    int w=0,c=1; char ch=getchar();
    while (ch<'0' || ch>'9')
      {
        if (ch=='-') c=-1;
        ch=getchar();
      }
    while (ch>='0' && ch<='9')
      w=w*10+ch-'0',ch=getchar();
    return w*c;
}

int main()
{
    T=read();
    for (i=1;i<=T;i++)
      {
        tot=ans=0;
        gets(s);
        for (j=0;j<strlen(s);j++)
          if (s[j]==h[tot])
            {
              if (tot==8) ans++;
              tot=(tot+1)%9;        
            }
        printf("%d\n",ans);
      }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章