[UVa #12289] One-Two-Three

tolelom·2022년 7월 5일
0

UVa

목록 보기
13/20

문제 설명

문제 링크
문자열이 주어지면 그 문자열이 one, two, three 중 어떤 것인지 확인하라.
단 문자열에 최대 한 문자가 틀릴 수 있고 문자열의 길이는 정확하게 입력된다.

알고리즘

문자열의 길이로 three를 판별할 수 있고 one과 two는 one과 비교해서 2글자 이상 같으면 one으로 판별해주었다.

코드

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000

int t;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    for (int tc = 1; tc <= t; tc++){
        string s;
        cin >> s;

        if (s.length() == 3) {
            int cnt = 0;
            if (s[0] == 'o') cnt++;
            if (s[1] == 'n') cnt++;
            if (s[2] == 'e') cnt++;

            if (cnt >= 2) cout << 1 << '\n';
            else cout << 2 << '\n';
        }
        else cout << 3 << '\n';
    }
}
profile
이것 저것 작성하는 기술 블로그

0개의 댓글