题解 UVA12289 【One-Two-Three】

· · 题解

给rmj水题写题解ing

因为three有 5 个字母,其他有三个字母,先判断长度,但one和two如何判断呢?

对于每个单词最多会错一个字母

所有先判断他是不是和one差一个字母;是输出 1,否则输出 2

code:

#include<bits/stdc++.h>
using namespace std;
string a,one="one";
int n;
int main()
{
    cin>>n;
    while(n--)
    {
        cin>>a;
        if(a.length()==5)
        {
            cout<<3<<endl;
            continue;
        }
        for(int i=0,wrong=0;i<3;i++)
        {
            if(one[i]!=a[i])wrong++;
            if(wrong>1)
            {
                cout<<2<<endl;
                goto AWA;//跳出 
            }
        } 
        cout<<1<<endl;
        AWA:
            ;
    } 
    return 0;
}