출처: https://train.usaco.org/usacogate


문제 설명

Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.

Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also print the value of that palindromic square. Use the letters 'A', 'B', and so on to represent the digits 10, 11, and so on.

Print both the number and its square in base B.

입력 양식

A single line with B, the base (specified in base 10).

출력 

Lines with two integers represented in base B. The first integer is the number whose square is palindromic; the second integer is the square itself. NOTE WELL THAT BOTH INTEGERS ARE IN BASE B!

입력 예

10

출력 예

1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696


문제 풀이 내용

십진수 (1<= N <= 300) 중에서 N^2 이 이진수부터 20진수(2<=B <=20)  중에 주어진 진법으로 변환했을때 Palindrome 이 되는 모든 수를 찾아서 출력하는 것이다. N 에 대해서 루프를 돌면서, N^2 를 주어진 진법으로 바꿔서, palindrome 인지 확인하고 해당하는 idx=N을 결과값 목록에 넣어둔다. 출력하면서, N, N^2 주어진 진법으로 변환해서 출력한다.

프로그램 내용

더보기
#define MAX_BASE 21
#define MAX_NUM 301
#define MAX_DIGIT 21

/// 10진수 이상의 진법에서 사용하는 문자로 변경, ex) 11 -> B
char reVal(int num);

// Convert input number is given base 
// by repeatedly dividing it by base and taking remainder
char *convert_Base(char str[], int inputNum, int base );

bool check_palindrome(string input);
{
    bool check = false;

    if (input == string(input.rbegin(), input.rend()))
    {
        check = true;
    }
    return check;
};

int main() {
    // Read Base
    int base_Num = 0;
    fin >> base_Num;

    // Convert all N^2 with Base B -> vector <string>
    for(int idx=0; idx < MAX_NUM ; ++idx)
    {
    }

    // Convert all N with Base B -> vector <string>
    for(int idx=0; idx < result.size(); ++idx)
    {
    }

 

Chapter 1. Getting started

 

'USACO Training' 카테고리의 다른 글

Problem 1.4.2 Mixing Milk  (0) 2019.09.12
Problem 1.3.6 Dual Palindromes  (0) 2019.09.08
Problem 1.3.4 Name That Numbers  (0) 2019.09.07
Problem 1.3.3 Transformations  (0) 2019.09.07
Problem 1.3.2 Milking Cow  (0) 2019.09.07

+ Recent posts