Holes(ACM ICPC 2008–2009, NEERC, Northern Subregional Contest Problem H)

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;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值