본문 바로가기

Algorithm

(C++) - 백준(BOJ) 14935번 : FA

반응형

https://www.acmicpc.net/problem/14935

 

14935번: FA

정수 x가 FA수 라면 FA를 출력하고, 아니라면 NFA를 출력한다.

www.acmicpc.net

간단한 수식 문제였습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
using namespace std;
string fa(string x)
{
    string tmp;
    tmp = ((x[0])-'0' * x.size()) + '0';
    return tmp;
}
int main() {
    string x;
    cin >> x;
    for (int i = 0; i < x.size(); i++)
    {
        x = fa(x);
    }
    if (x.size() == 1)
        cout << "FA" << '\n';
    else
        cout << "NFA" << '\n';
}
cs