출처: https://train.usaco.org/usacogate
문제 설명
A number that reads the same from right to left as when read from left to right is called a palindrome. The number 12321 is a palindrome; the number 77778 is not. Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome.
The number 21 (base 10) is not palindrome in base 10, but the number 21 (base 10) is, in fact, a palindrome in base 2 (10101).
Write a program that reads two numbers (expressed in base 10):
N (1 <= N <= 15)
S (0 < S < 10000)
and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10).
Solutions to this problem do not require manipulating integers larger than the standard 32 bits.
입력 양식
A single line with space separated integers N and S.
출력
N lines, each with a base 10 number that is palindromic when expressed in at least two of the bases 2..10. The numbers should be listed in order from smallest to largest.
입력 예
3 25
출력 예
26
27
28
문제 풀이
숫자 N과 S를 읽어서, S보다 큰 수중에서 이진법~십진법으로 바꿨을때 palindrome 이 두번 이상되는 N개의 수를 작은 순서대로 출력하는 문제이다. S에서 시작되는 루프를 돌리면서, 이진법~10진법으로 변환해서 palindrome 이 되는 경우가 2번 되면, 그 숫자를 결과 목록에 추가하고, 결과 목록이 N개가 되면 출력한다.
프로그램 내용
#define MAX_N 16
#define MAX_S 100001
#define MAX_DIGIT 21
/// 10 이상의 수를 영문자로 표시한다. ex) 12 -> C
char reVal(int num);
/// 특정 진법으로 변환한다.
char *convert_Base(char str[], int inputNum, int base );
bool check_palindrome(string input);
int main() {
// Read Base
int base_N = 0, base_S = 0;
fin >> base_N >> base_S;
vector <int> result;
// base 2 ~ base 10 check palindrom from S
// count == N break
int t_count = 0;
for (int idx = base_S+1; idx < MAX_S ; ++idx)
{
...
if(t_count >= base_N)
break;
}
for(auto it : result)
fout << it << "\n";
Chapter 1. Getting started
'USACO Training' 카테고리의 다른 글
Problem 1.4.3 Barn Repair (0) | 2019.09.12 |
---|---|
Problem 1.4.2 Mixing Milk (0) | 2019.09.12 |
Problem 1.3.5 Palindromic Squares (0) | 2019.09.08 |
Problem 1.3.4 Name That Numbers (0) | 2019.09.07 |
Problem 1.3.3 Transformations (0) | 2019.09.07 |