Overturned Numbers
Little Pierre was surfing the Internet and came across an interesting puzzle:
Problem illustration
What is the number under the car?
It took some time before Pierre solved the puzzle, but eventually he understood that there were overturned numbers 86, 88, 89, 90, and 91 in the picture and the answer was the number 87.
Now Pierre wants to entertain his friends with similar puzzles. He wants to construct a sequence of n numbers such that its overturning produces a consecutive segment of the positive integers. Pierre intends to use one-digit integers supplemented with a leading zero and two-digit integers only. To avoid ambiguity, note that when the digits 0, 1, and 8 are overturned, they remain the same, the digits 6 and 9 are converted into each other, and the remaining digits become unreadable symbols.
Input
The only line contains the number n of integers in a sequence (1 ≤ n ≤ 99).
Output
If there is no sequence of length n with the above property, output “Glupenky Pierre” (“Silly Pierre” in Russian). Otherwise, output any of such sequences. The numbers in the sequence should be separated with a space.
Example
input | output |
---|---|
2 | 11 01 |
99 | Glupenky Pierre |
问题描述
输入一个正整数n,输出n个数,要求这n个数倒过来是n个连续的整数,如:11 01,倒过来就是10 11。如果做不到就输出“Glupenky Pierre”。
问题分析
因为倒过来还是数字的数只有:0,1,6,8,9。所以一个个列出来就可以看出来了。
00 | 01 | 06 | 08 | 09 |
---|---|---|---|---|
10 | 11 | 16 | 18 | 19 |
60 | 61 | 66 | 68 | 69 |
80 | 81 | 86 | 88 | 89 |
90 | 91 | 96 | 98 | 99 |
显然合适的n有:1,2,3,4。相应输出合题意的就可以了。
c++程序如下
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
scanf_s("%d", &n);
if (n == 1) printf("10\n");
else if (n == 2) printf("11 01\n");
else if (n == 3) printf("06 68 88\n");
else if (n == 4) printf("16 06 68 88\n");
else printf("Glupenky Pierre\n");
return 0;
}