선택은 나의 것

[BOJ 백준] 16968번 차량 번호판 1 본문

☽ Algorithm/BOJ

[BOJ 백준] 16968번 차량 번호판 1

Algoribi 2020. 7. 29. 11:59

문제

BOJ16968 : https://www.acmicpc.net/problem/16968

 

16968번: 차량 번호판 1

00부터 99까지 총 100가지 중에서 00, 11, 22, 33, 44, 55, 66, 77, 88, 99가 불가능하다.

www.acmicpc.net

접근

주어진 조건을 통해 만들 수 있는 번호판의 개수를 구하는 문제이다. 이때 연속된 문자 혹은 숫자는 같을 수 없다. 따라서 이전에 위치한 것이 숫자인지 문자인지 현재 위치와 확인해 가면서 경우의 수에 따른 답을 구해주면 된다.

코드

#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int ans = 1;
    char fl = s[0];
    if (fl == 'd')
        ans *= 10;
    else
        ans *= 26;
    for (int i = 1; i < s.size(); i++) {
        if (fl == 'c') {
            if (s[i] == 'c')
                ans *= 25;
            else
                ans *= 10;
        } else {
            if (s[i] == 'd')
                ans *= 9;
            else
                ans *= 26;
        }
        fl = s[i];
    }
    cout << ans;
    return 0;
}

 

깃 허브 주소 : https://github.com/algoribi/algorithm-study

Comments