One-Two-Three

Your little brother has just learnt to write one, two and three, in English. He has written a lot of those
words in a paper, your task is to recognize them. Note that your little brother is only a child, so he
may make small mistakes: for each word, there might be at most one wrong letter. The word length is
always correct. It is guaranteed that each letter he wrote is in lower-case, and each word he wrote has
a unique interpretation.

Input

The first line contains the number of words that your little brother has written. Each of the following
lines contains a single word with all letters in lower-case. The words satisfy the constraints above: at
most one letter might be wrong, but the word length is always correct. There will be at most 10 words
in the input.

Output

For each test case, print the numerical value of the word.

Sample Input

3
owe
too
theee

Sample Output

1
2
3

题目

第一眼看到这道题的时候,感觉挺简单的,然后就不停想简单的方法,最后wa了好多发,最后终于放弃找简单的方法,老老实实地用递归找最长公共子序列,然后就A了.比赛结束之后看了别人的代码,原来真的有简单的方法抓狂

唉~~~,这次就当是练了练dp

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
char a[900];
char a1[6]={"pone"};
char a2[6]={"ptwo"};
char a3[9]={"pthree"};
int c1[10][10],c2[10][10],c3[10][10];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(c1,0,sizeof(c1));
        memset(c2,0,sizeof(c2));
        memset(c3,0,sizeof(c3));
        int flag1=0,flag2=0,flag3=0;
        scanf("%s",a+1);
        int l=strlen(a+1);
        for(int i=1;i<=l;i++)
        {
            for(int j=1;j<=3;j++)
            {
                if(a[i]==a1[j])
                {
                    c1[i][j]=c1[i-1][j-1]+1;
                }
                else
                {
                    c1[i][j]=max(c1[i-1][j],c1[i][j-1]);
                }

            }

            for(int j=1;j<=3;j++)
            {
                if(a[i]==a2[j])
                {
                    c2[i][j]=c2[i-1][j-1]+1;
                }
                else
                {
                    c2[i][j]=max(c2[i-1][j],c2[i][j-1]);
                }
            }
            for(int j=1;j<=5;j++)
            {
                if(a[i]==a3[j])
                {
                    c3[i][j]=c3[i-1][j-1]+1;
                }
                else
                {
                    c3[i][j]=max(c3[i-1][j],c3[i][j-1]);
                }
            }
        }
        flag1=c1[l][3];
        flag2=c2[l][3];
        flag3=c3[l][5];
        if(flag1>=flag2&&flag1>=flag3)
        {
            printf("1\n");
            continue;
        }
        if(flag2>=flag1&&flag2>=flag3)
        {
            printf("2\n");
            continue;
        }
        if(flag3>=flag2&&flag3>=flag1)
        {
            printf("3\n");
            continue;
        }
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值