1952-Lucky Sum of Digits

来源:互联网 发布:51单片机操作系统 编辑:程序博客网 时间:2024/05/16 06:43

Description

在数字界有一类被叫做幸运数的数,其实幸运数的组成很简单。如果一个数所有位数上的数字都是4或7的话就叫做幸运数。比如444444, 44747是幸运数而57774747就不是。

现在mwy遇到了一个小问题,他只知道一个幸运数所有位数上数字之和,他想知道这个数最小会是多少,聪明如你,快来帮帮我们的mwy吧。

Input

输入一个数n(n<=300)。

Output

如果可以找到这样的幸运数,就输出这个幸运数,否则就输出-1。






下附AC代码:
#include<stdio.h>int main() {int n, i;scanf("%d", &n);int s = 0, f = 0;s = n / 7;if (0 == (n - 7 * s) % 4) {f = (n - 7 * s) / 4;}elsewhile (s--) {if (0 == (n - 7 * s) % 4) {f = (n - 7 * s) / 4;break;}}if (0 == n || -1 == s) {printf("-1");}for (i = 0 ; i < f; ++i) {printf("4");}for (i = 0 ; i < s; ++i) {printf("7");}printf("\n");return 0;}


原题链接:http://acm.hznu.edu.cn/OJ/problem.php?cid=1091&pid=25