Description
Input file: holes.in
Output file: holes.out
Time limit: 3 seconds
Memory limit: 256 megabytes
You may have seen a mechanic typewriter — such devices were widespread just 15 years ago, beforecomputers replaced them. It is a very simple thing. You strike a key on the typewriter keyboard, thecorresponding type bar rises, and the metallic letter molded into the type bar strikes the paper. Theart of typewriter typing, however, is more complicated than the art of computer typing. You shouldstrike keys with some force otherwise the prints will not be dark enough. Also you should not overdo itotherwise the paper will be damaged.
Imagine a typewriter with very sharp letters, which cut the paper instead of printing. It is clear thatdigit 0 being typed on the typewriter makes a nice hole in the paper and you receive a small paper ovalas a bonus. The same happens with some other digits: 4, 6, 9 produce one hole, and 8 produces twotouching holes. The remaining digits just cut the paper without making holes.
The Jury thinks about some exhibition devoted to the oncoming jubilee of Pascal language. One of theideas is to make an art installation, consisting of an empty sheet of paper with exactly h (0 ≤ h ≤ 510)holes made by typing a non-negative integer number on the cutting typewriter described above. Thenumber must be minimal possible and should not have leading zeroes. Unluckily we are too busy withpreparing the ACM quarter- and semifinals, so we need your help and ask you to write a computerprogram to generate the required number.
Input
A single integer number h — the number of holes.
Output
The integer number which should be typed.
Sample Input
0
Sample Output
1
Sample Input
1
Sample Output
0
Sample Input
15
Sample Output
48888888
Sample Input
70
Sample Output
88888888888888888888888888888888888
题解:读懂,就会了吧。。。。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define For(i,n) for(int i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int maxn = 600;
const double Pi = acos(-1);
const int INF = 0x3f3f3f3f;
int main()
{
freopen("holes.in","r",stdin);
freopen("holes.out","w",stdout);
int a[maxn] = {0};
int cnt = 0;
int n;
bool flag = false;
while(cin >> n)
{
cnt = 0;
flag = false;
mem(a);
if(n < 2)
flag = true;
while(n>=2)
{
a[cnt++] = 8;
n-=2;
}
if(flag)
{
if(n == 0)
a[cnt++] = 1;
else
{
a[cnt++] = 0;
}
}
else
{
if(n)
a[cnt++] = 4;
}
for(int i=cnt-1; i>=0; i--)
cout << a[i];
}
return 0;
}