ZeroJudge C562: Puyu Loves Numeral Theory

For Puyu, who is proficient in number theory problems, there's supposedly no number theory problem he can't solve. So, when a Capture The Flag (CTF) event known for its tricky challenges arrived from the heavens to test him, he was ready for the showdown.

CTF provided Puyu with several sets of numbers, representing input values and the corresponding function results. He was tasked with identifying the pattern among them and answering questions about the results of certain numbers posed by the CTF.

函數如下:

  • F ( 110 ) = 1
  • F ( 163 ) = 1
  • F ( 223 ) = 0
  • F ( 119 ) = 1
  • F ( 278 ) = 2
  • F ( 821 ) = 2

Now please observe the pattern of the function and write a program to help Puyu complete the challenge!

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
EOF inputs: each test case consists of a number N, representing the number CTF is asking Puyu about.
( 0 <= N <= 2147483649 )
Each line should output a number F(N). F(N) will always be within the int range.
223
821
734
0
2
0

Thought Process

This problem involves counting the number of holes in each digit of N. For example, F(0) would be 1, and F(8) would be 2. You can input N as a string and then use if statements for the check. The sample code uses a map to perform this check, allowing you to directly add F(N) to the answer.

Sample Code-ZeroJudge C562: Puyu Loves Numeral Theory

#include <iostream>
#include <map>
using namespace std;

int main() {
    map<char, int>MAP;
    MAP['0'] = 1;
    MAP['6'] = 1;
    MAP['8'] = 2;
    MAP['9'] = 1;
    string N;
    while (cin >> N)
    {
        int ans = 0;
        for (int i = 0; i<N.length(); i++)
        {
            ans += MAP[N[i]];
        }
        cout << ans << "\n";
    }
}

//ZeroJudge C562
//Dr. SeanXD

Comments